Insufficient Permission error for Google Drive iOS - ios

I am using Google SignIn for authentication in one of my iOS application. With that I am defining all possible scopes for Google drive use but still getting the following error. I am creating different files on Google Drive.
Domain=com.google.GTLRErrorObjectDomain Code=403 "Insufficient Permission"
UserInfo={GTLRStructuredError=GTLRErrorObject 0x170450d10: {message:"Insufficient
Permission" errors:[1] code:403}, NSLocalizedDescription=InsufficientPermission
I am defining scopes with Google SignIn as:
[[GIDSignIn sharedInstance].scopes
arrayByAddingObject:#[kGTLRAuthScopeDriveFile,kGTLRAuthScopeDrive,
kGTLRAuthScopeDriveMetadata]];
Google Drive API is enable on Google Console but still I do not know why I am getting this error. I also tried to turn on "OAuth 2.0" for Google Drive service on console but google is not allowing me and automatically turn it off. Any help will be appreciated.

Google changed it's authentication policy for it's API's. Now native web views for OAuth flow is not allowed by them but users are pushed to use OS browsers. They also introduced Google SignIn button SDK that is used for user login, if user wants to use Google Service. Google SignIn button(GIDSign) handle some authentication flow for users. Users can also use updated "GMTAppAuth" and "AppAuth" for implementation of GTMFetcherAuthorizationProtocol for authorizing request for AppAuth. I was using Google Drive API in one of my application and using "GTMOAuth2ViewControllerTouch" for Google Sign In and authentication but after update, it stopped working. In my above mentioned question, I am using Google SignIn for authentication. In old code, you can use Authentication NSString* constants "GTLRAuthScopeDriveFile" to define scope but now they changed the way and that's why I am getting error.
Old way of defining scope:
- (GTMOAuth2ViewControllerTouch *)createAuthController {
NSArray *scopes = [NSArray arrayWithObjects:kGTLRAuthScopeDriveFile, kGTLRAuthScopeDrive,nil];
authController = [[GTMOAuth2ViewControllerTouch alloc]
initWithScope:[scopes componentsJoinedByString:#" "]
clientID:kClientID
clientSecret:nil
keychainItemName:kGTMAppAuthKeychainItemName
delegate:self
finishedSelector:#selector(viewController:finishedWithAuth:error:)];
return authController;
}
New corrected way:
NSString *driveFile = #"https://www.googleapis.com/auth/drive.file";
[GIDSignIn sharedInstance].scopes = [currentScopes arrayByAddingObject:driveFile];

Related

Connection using Gmail OAuth 2.0

I am trying to connect to Gmail using OAuth 2.0.
However, it is impossible to test that you can not join the risky-access-by-unreviewed-apps group.
Does Google prevent participation in the group? Or is there any other way?
The method for connection refers to the following article.
https://developers.google.com/gmail/imap/xoauth2-protocol
I asked a question in google API pending email.
After that the contents of the homepage was updated.
I can not see sentences to register in the risky-access-by-unreviewed-apps group.
I developed on iOS.
The problem was that G-Mail connection authorization not added privileges at login was not done.
I solved the problem by adding G-Mail permissions.
Additional source of authority
[GIDSignIn sharedInstance].scopes = [NSArray arrayWithObjects:#"https://www.googleapis.com/auth/userinfo.profile", #"https://www.googleapis.com/auth/userinfo.email", #"https://mail.google.com", nil];
IMAP JAVA connection test : https://github.com/google/gmail-oauth2-tools/wiki/JavaSampleCode

Share to Google+ After Login With Google SignIn

Before the Google SignIn API this is how I shared an image:
let shareBuilder = GPPShare.sharedInstance().nativeShareDialog()
shareBuilder.setPrefillText(someText)
shareBuilder.attachImage(anImage)
shareBuilder.open()
But now, after I sign in with the new API and try to share I get an error that says: "User must be signed in to use the native sharebox"
How can I fix this error?
Google+ SDK is deprecated.If you want to share to google +,you can only their way Basic sharing without signing in.However,I don't know how to share an image within their newest way.

Google Signin for iOS - YouTube Channel ID

I have follows the instructions and implement Google Signin for iOS in test application.
After getting the user profile & token, I want to get the user YouTube channel ID.
I have tried to use the user access token with the following URL but I got exception of "Insufficient Permission"
https://www.googleapis.com/youtube/v3/subscriptions?part=snippet&maxResults=50&mine=true&access_token={oauth_token}
How can I do this in Swift?
Google Signin for iOS implementation which allow you yo signin with your google account. In order to have that ability to get YouTube data it require additional scope configuration as follows:
let scope: NSString = "https://www.googleapis.com/auth/youtube.readonly"
let currentScopes: NSArray = GIDSignIn.sharedInstance().scopes
GIDSignIn.sharedInstance().scopes = currentScopes.arrayByAddingObject(scope)
Now, you can run the following YouTube data API with Access Token:
https://www.googleapis.com/youtube/v3/channels?part=id&mine=true&access_token={oauth_token}
The access token, you will get from user.authentication.accessToken

Unexpected 403 error from Google

I'm currently maintaining an iOS application developed by someone else. The application worked fine until today when suddenly it started returning 403 codes every time I tried to connect to Google Drive. This is the full error:
An error occurred: Error Domain=com.google.GTLJSONRPCErrorDomain
Code=403 "The operation couldn’t be completed. (Access Not Configured.
Please use Google Developers Console to activate the API for your
project.)" UserInfo=0x17db6180 {error=Access Not Configured. Please
use Google Developers Console to activate the API for your project.,
GTLStructuredError=GTLErrorObject 0x17db5ef0: {message:"Access Not
Configured. Please use Google Developers Console to activate the API
for your project." code:403 data:[1]},
NSLocalizedFailureReason=(Access Not Configured. Please use Google
Developers Console to activate the API for your project.)}
I've enabled Google Drive in the Google Console and included the codes google gave me but I still can't overcome this error.
I'm using Google APIs Client Library for Objective-C to connect to GDrive.
Hi I too got similar error in my mac machine 1 month before, I added DNS server 8.8.8.8 and worked fine. May be similar option will be available in iOS device too that can help you.
I believe this issue is because of "API Key". Please make sure you have used API Key in the project and if you have already used that than check the validity of that key.
Take a look at the errors for BigQuery https://developers.google.com/bigquery/troubleshooting-errors Google returns 403 errors for a number of different situations including some quota limitations.
Perhaps with Drive they use the same types of errors
I think it is a recent change I believe.
In google project console check if access to following is enabled:
Contacts
Google+
Also somebody suggested me to set "Referers" to "Any referer allowed". But not sure about it.
Please try.
Here is fix to this Issue :
You just have to add the scope kGTLAuthScopeDriveFile in your Request. Please refer to below code for its implementation.
GTMOAuth2ViewControllerTouch *authController;
NSArray *scopes = [NSArray arrayWithObjects:kGTLAuthScopeDriveFile, nil];
authController = [[GTMOAuth2ViewControllerTouch alloc]
initWithScope:[scopes componentsJoinedByString:#" "]
clientID:kClientID
clientSecret:kClientSecret
keychainItemName:kKeychainItemName
delegate:self
finishedSelector:#selector(viewController:finishedWithAuth:error:)];
IMPORTANT : Now you have to authorize your user again so that The Permission can be granted to the user correctly.
After that Your Code will work Perfectly !
This appeared to be on Google's side. One phone call to them with no changes on our side seems to have fixed it.

iOS: OAuth2Client and Google

I'm trying to get Google's OAuth2 working for user verification in an iOS app.
I'm using the OAuth2Client api but cannot get it working with google. It appears that google only accepts http://localhost or urn:ietf:wg:oauth:2.0:oob as the redirect url. Stopping me from using a custom schema to trigger a switch back to my app.
The code looks like this:
[[NXOAuth2AccountStore sharedStore] setClientID:#"<client-id>"
secret:#"<secret>"
authorizationURL:[NSURL URLWithString:#"https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile"]
tokenURL:[NSURL URLWithString:#""]
redirectURL:[NSURL URLWithString:#"http://localhost"]
forAccountType:#"Google"];
[[NXOAuth2AccountStore sharedStore] requestAccessToAccountWithType:#"Google"];
When I run it, Safari appears and asks for access, but then gets stuck because I cannot redirect back to the app.
Anyone know how to make this work or do I need a different api? Note: I cannot currently get access to Google toolbox OAuth2 kit ATM.
Finally got the GTM-OAuth2 code and that appears to be working.

Resources