gapi.auth2 can not get access_token

691 views
Skip to first unread message

robbe clerckx

unread,
Aug 3, 2016, 2:21:54 PM8/3/16
to Google API JavaScript Client
Hi all,

I'm trying to implement resumable uploads for youtube using the javascript client API. I've managed to get the login working using the g-signin2 button, but I can't get the access_token to send with the requests. This is how I render the sign in button:
<span
  class="g-signin2"
  data-onsuccess="youtubeUploaderSigninCallback"
</span>

I'm using code edited samples from https://developers.google.com/youtube/v3/code_samples/javascript#upload_video for resumable uploads using XHR.
But these examples use the auth functions marked as deprecated here: https://developers.google.com/api-client-library/javascript/reference/referencedocs
So the main thing I changed is using the auth2 and g-signin2 instead of result.access_token and g-signin.

So I've been trying to use the "auth2" functions to get the access tokens, but the access_token property is undefined when I execute the following code
gapi.auth2.getAuthInstance().currentUser.get().getAuthResponse()


So these are my options, I guess:
  1. find a way to get the access token out of the user object
    • (I found that user.hg.access_token contains the token I need
    • but "hg" seems a minified property to me
    • so I'm not intending to use this as it might change with updates
  2. add progress events to gapi.client.request()
    • but the xhr object doesn't seem to be exposed
  3. use code documented as deprecated
Can anyone help me with this? I've been looking for an acceptable solution for a few hours and I feel like crying now... all alone and desperate.

Thanks in advance,
Robbe

robbe clerckx

unread,
Aug 3, 2016, 2:43:55 PM8/3/16
to Google API JavaScript Client
PS: I've also posted this on stack overflow since I couldn't decide which was better: http://stackoverflow.com/questions/38751262/gapi-auth2-can-not-get-access-token

Op woensdag 3 augustus 2016 20:21:54 UTC+2 schreef robbe clerckx:
Reply all
Reply to author
Forward
0 new messages