13

For my project i have completed the entire auth flow in a server-side manner, writing my access codes and tokens to text files that can be used by my client-side application.

I am attempting to use gapi.auth.setToken() from the JS CLient Library to 'authorize' my application using this externally generated access token.

The problem occurs when i finally send requests to the various API's i need to access. i receive this error message:

{code: 403, message: "Daily Limit for Unauthenticated Use Exceeded. Continued use require signup.", data: Array[1], error: Object}

This leads me to believe that gapi.auth.setToken() is not doing what i expected it to do.

What am i missing here?

locksem
  • 315
  • 3
  • 16
  • Your diagnosis is probably correct. You should trace the http to confirm. You're looking for an Authorization header. Can you paste the code where you call setToken(), and also where you use the token to make your API call. – pinoyyid Jan 17 '14 at 06:05
  • Once a function to get the access token from file has finished, this is the call back: (where accessToken holds the entire token object - unparsed) function setMyAuthToken() { gapi.auth.setToken(accessToken); } – locksem Jan 17 '14 at 11:09
  • Have you enabled all the APIs you wanna access in your API console? – Emily Jan 17 '14 at 22:33
  • I have indeed, and i am able to manually write GET requests to get authorized access to those API's, the problem lies in trying to set the access token for the application (using gapi.auth.setToken() ) - so that i can use the API client interfaces to make authenticated requests. After some tinkering around, im going to assume this is not possible unless gapi.auth.authorize has been used to authorize. – locksem Jan 18 '14 at 14:07

2 Answers2

25

This worked for me :

gapi.auth.setToken({
    access_token: "YOUR_TOKEN_HERE"
});

In fact this token object is the same as the one you get within the gapi.auth.authorize() callback. So if something doesn't works as expected, you can add more attributes from there to make it work. Anyway it's still a hack, although there is official documentation on it... Crappy gapi.

rvivant
  • 376
  • 3
  • 6
2

I'm running into similar issues. The reason this occurs is because setToken() requires the OAuth2 token object, not the OAuth2 access_token which is merely a string. I'm sticking with manually written GET requests until developers can just set the access token, similar to how the ruby client works.

Rajesh
  • 10,318
  • 16
  • 44
  • 64
williamrfry
  • 350
  • 3
  • 11
  • How can I get the OAuth2 token **object**. I can see I have the OAuth2 **access_token** (string) in DB. – oskrgg Jan 25 '21 at 21:51