问题
I'm working on an IOS app using Swift that requires accessing to the user's YouTube subscriptions. After adding all scopes I need on Google Cloud Platform and implementing GoogleSignIn in Firebase. I sign in (GIDSignInButton), then I get the error shown down below after making this request:
https://www.googleapis.com/youtube/v3/subscriptions?part=snippet%2CcontentDetails&mine=true&key=\(apiKey)&access_token=\(Access_Token)
.
The Access_Token is the one I got after I call:
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error?){
user.authentication.accessToken
....}
The error I'm getting:
["error": {
code = 403;
errors = (
{
domain = global;
message = "Insufficient Permission";
reason = insufficientPermissions;
}
);
message = "Request had insufficient authentication scopes.";
status = "PERMISSION_DENIED";
}]
In App Delegate I set this:
GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID
回答1:
I had the same problem and, if I remember correctly, it occurred when my OAuth consent verification status was unverified. What I did to make it work was, in addition to supplying scopes in the Google dashboard, I added them programmatically before signing in.
GIDSignIn.sharedInstance().scopes.append("https://www.googleapis.com/auth/youtube.upload")
GIDSignIn.sharedInstance().signIn()
回答2:
First, discard the parameter key=(apiKey)
; the authorization is based solely on access_token=(Access_Token)
.
Do note that the access tokens are short-lived. You may issue a HTTPS GET
request to:
https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=(Access_Token)
for to see whether your access token is still valid. The response provided would look either as:
{
"error": "invalid_token",
"error_description": "Invalid Value"
}
or as:
{
"issued_to": "...",
"audience": "...",
"scope": "...",
"expires_in": 3599,
"access_type": "offline"
}
Then double-check that you have the required scopes attached to that access token in case it's valid.
来源:https://stackoverflow.com/questions/64180265/youtube-data-api-error-403-insufficient-permission