14

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?

4
  • 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. Commented Jan 17, 2014 at 6: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); } Commented Jan 17, 2014 at 11:09
  • Have you enabled all the APIs you wanna access in your API console? Commented Jan 17, 2014 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. Commented Jan 18, 2014 at 14:07

2 Answers 2

27

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.

Sign up to request clarification or add additional context in comments.

1 Comment

but how to get this access token @rvivant
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.

1 Comment

How can I get the OAuth2 token object. I can see I have the OAuth2 access_token (string) in DB.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.