Error: Grant credentials are invalid 2022
Hi, I am getting an error when I try to use box_subject_type and box_subject_id as the user and user id when trying to generate an access token.
-
Hello Alex,
I am trying to upload files via API, and enterprise id doesn't work for that.
Although, I am able to successfully generate an access token with enterprise id, I get this error when running my upload code:
{"type":"error","status":404,"code":"not_found","context_info":{"errors":[{"reason":"invalid_parameter","name":"parent","message":"Invalid value 'd_155054681560'. 'parent' with value 'd_155054681560' not found"}]},"help_url":"http:\/\/developers.box.com\/docs\/#errors","message":"Not Found","request_id":"hbgddxh0allyle98"}
This is the code I am using.
That is why I am trying to use user and user id in box_subject_id and box_subject_type, but I am getting this error.
-
Hello Albert Chen
I see that in your example you created a connection with directly passed access token instead of using one of these constructor:
BoxCCGAPIConnection api = BoxCCGAPIConnection.applicationServiceAccountConnection(
"client_id",
"client_secret",
"enterprise_id"
);BoxCCGAPIConnection api = BoxCCGAPIConnection.userConnection(
"client_id",
"client_secret",
"user_id"
);
Please visit this documentation page for more details about how to use CCG https://github.com/box/box-java-sdk/blob/main/doc/authentication.md#client-credentials-grant
User connectionThe reason why user BoxCCGAPIConnection.userConnection() is not working for you is probably due to missing your app's authorization by an admin.Please go to your app in https://app.box.com/developers/console/. Then go to "Authorization" tab at the top and click "Review and Submit". After that your admin should accept this changes.
Account Service connection
The reason why you cannot upload a file using enterprise connection is that account service is separate from the Box accounts of the application developer and the enterprise admin of any enterprise that has authorized the app — files stored in that account are not accessible in any other account by default, and vice versa. https://developer.box.com/guides/getting-started/user-types/service-account/.
So after you created an BoxCCGAPIConnection.applicationServiceAccountConnection() connectionyou should use `asUser()` function described here https://github.com/box/box-java-sdk/blob/main/doc/authentication.md#as-user to make API calls on behalf of managed user which has access to this folder `155054681560`. But in order to do this you should firstly turn on "Make API calls using the as-user header" on your https://app.box.com/developers/console app on "Configuration" tab and "Advanced Features" section. Then you should go to "Authorization" tab at the top and click "Review and Submit". After that your admin should accept this changes.
Please let me know if it helped you.
Regards,Artur
投稿コメントは受け付けていません。
コメント
4件のコメント