Can I use google drive sdk with authentication info from google sign-in sdk on iOS? -


we have login module uses google sign-in sdk. google sign-in gives gidauthentication object after login succeed.

now want access user's google drive google drive sdk needs gtmoauth2authentication provide authentication info. can use gidauthentication construct gtmoauth2authentication drive sdk?

manually assign accesstoken value seems not working(drive scope added).

yes can!

use following steps:

  1. follow steps add google signin described in: https://developers.google.com/identity/sign-in/ios/start-integrating. make sure enable google drive api project.

  2. when initialising sign-in object, don't forget add google drive api scope:

    func application(application: uiapplication, didfinishlaunchingwithoptions launchoptions: [nsobject: anyobject]?) -> bool {     // initialize sign-in     var configureerror: nserror?     gglcontext.sharedinstance().configurewitherror(&configureerror)     assert(configureerror == nil, "error configuring google services: \(configureerror)")      gidsignin.sharedinstance().delegate = self      // use here whatever auth scope wish (e.g., kgtlauthscopedrivereadonly,      // kgtlauthscopedrivemetadata, etc..)     // can append more scopes allow access more services,     // other google drive.     gidsignin.sharedinstance().scopes.append(kgtlauthscopedrive)      return true } 
  3. in appdelegate (or other accessible place), add:

    var myauth: gtmfetcherauthorizationprotocol? = nil 
  4. in signin delegate function (assuming here set in appdelegate), add following code:

    func signin(signin: gidsignin!, didsigninforuser user: gidgoogleuser!, witherror error: nserror!) {     if (error == nil) {         // logged google services successfully!          // save relevant details user.authentication refresh token when needed.                // set gtmoauth2authentication authoriser google drive service         myauth = user.authentication.fetcherauthorizer()     } else {         // error signing google services     } } 
  5. last, wherever set googleservicedrive, can set authoriser, setting:

    let service = gtlservicedrive() service.authorizer = (uiapplication.sharedapplication().delegate as! appdelegate).myauth 
  6. now can use example code google

    if let authorizer = service.authorizer, canauth = authorizer.canauthorize canauth {     // service authorised , can used queries } else {     // service not authorised  } 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -