problem with DriveFile scope in ios app with new rest api

245 views
Skip to first unread message

Gerrit Kleyn Winkel

unread,
Sep 30, 2016, 10:00:54 AM9/30/16
to GTM OAuth 2 Discussion
Hi,

I'm adding google drive access to my ios app using the new Rest api, but run into the following issue:

when I request kGTLRAuthScopeDriveFile scope access, i would expect a grant window asking me to grand access to files created by the app.
but it doens't, it only asks to grant access to "know who you are" and "view email address", only 2 things.
When I use kGTLRAuthScopeDrive it does ask to grant access to all files in the Drive + the two mentioned.

when I use kGTLRAuthScopeDriveFile, I am able to create files, but I can not read the, or delete them.
when I use kGTLRAuthScopeDrive, I am able to create files and I can read them and delete them.

unfortunately there is only an osx drive example in the rest sdk.

the old GTL sdk seems to do it as expected, at least de drive example included does.

is anyone else hving the same issue?

This is my call to ask for access:


SEL finishedSelector = @selector(viewController:finishedWithAuth:error:);

    GTMOAuth2ViewControllerTouch *authViewController =

    [[GTMOAuth2ViewControllerTouch alloc] initWithScope:kGTLRAuthScopeDrive

                                               clientID:kClientId

                                           clientSecret:kClientSecret

                                       keychainItemName:kKeychainItemName

                                               delegate:self

                                       finishedSelector:finishedSelector];

Thomas Van Lenten

unread,
Sep 30, 2016, 12:50:12 PM9/30/16
to GTM OAuth 2 Discussion
fyi - The scope string can actually be a merge of scopes, https://github.com/google/gtm-oauth2/blob/master/Source/GTMOAuth2Authentication.h#L396 can be used to generate the merging for you.

Auth scopes aren't iOS/macOS specific, so that part of the example should be the same between the two.

The GTL and GTLR examples should be able to do the same things.  Did you registry on the console so your client id is allowed drive access server side?  If that isn't enabled, the oauth signing likely will ignore those requested scopes (although I haven't confirmed that myself).

TVL

Gerrit Kleyn Winkel

unread,
Sep 30, 2016, 12:56:29 PM9/30/16
to GTM OAuth 2 Discussion
I fixed it my self.....

I used the old style fetcher method from the GTL examples, but now used the fetcher method from the GTLR example to get the contents of a file.
and that works fine.
the example is for osx, but the code is the same for ios.

old GTL style fetcher:

NSString *strUrlContent = myfile.webContentLink;

    GTMSessionFetcher *fetcher = [self.driveService.fetcherService fetcherWithURLString:strUrlContent];
    
    [fetcher beginFetchWithCompletionHandler:^(NSData *data, NSError *error) {
    
        if (error == nil) {
          
        }
    
    }];


new GTLR style fetcher:

GTLRQuery *query = [GTLRDriveQuery_FilesGet queryForMediaWithFileId:myfile.identifier];

    

    NSURLRequest *downloadRequest = [self.driveService requestForQuery:query];

    GTMSessionFetcher *fetcher = [self.driveService.fetcherService fetcherWithRequest:downloadRequest];

    

    [fetcher setCommentWithFormat:@"Downloading %@", myfile.name];

    

    [fetcher beginFetchWithCompletionHandler:^(NSData *data, NSError *error) {

    

        if (error == nil) {

           

        }

    

    }];

Reply all
Reply to author
Forward
0 new messages