Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use access token from GIDSignIn to use Google Drive SDK iOS

I have set up my project to sign in to a user's Google account using the Google Sign In framework. It works fine, but I want to use the access token that I get from the sign in to access the user's Google Drive. I am programming for iOS and have already set up the Drive SDK in my project. I feel like there should be a simple way of doing this. Thank You!

like image 851
user2430463 Avatar asked Apr 30 '15 00:04

user2430463


1 Answers

Recently experienced the same problem myself when attempting to use the Calendar API.

You can access the access token (and therefore use it in your URL Requests) like so:

if (GIDSignIn.sharedInstance().currentUser != nil) {
    let accessToken = GIDSignIn.sharedInstance().currentUser.authentication.accessToken
    // Use accessToken in your URL Requests Header
}    

Make sure to only call this method after the user has signed in, the check for current user will prevent a crash from implicitly unwrapping a nil value.

like image 60
Joshua Finch Avatar answered Sep 28 '22 08:09

Joshua Finch