Call gapi.auth.authorize for every request?

56 views
Skip to first unread message

James Colestock

unread,
Dec 14, 2015, 1:12:42 PM12/14/15
to Google API JavaScript Client
Good day everybody.  I was hoping people with a little more experience could give me some guidance.

I have a small, single-page application that uses a Google Apps Script Execution API project I created.  It has two scopes that require authentication via OAuth.  I am using the technique modeled in the example code in which 
gapi.auth.authorize

is called and its callback function uses 
gapi.client.request

to manipulate and return the API's data to the front-end. 

Everything works, however, I can only get my application to work if I call
gapi.auth.authorize

before every API request.  Each call appends another IFRAME to the web page.  I don't know whether this is the intended behavior or I am just ignorant to a better way of doing this.

If anyone could elaborate on the best/recommended way to make multiple/subsequest API requests, I would be quite appreciative!
 
Thank you!

Renaud Tarnec

unread,
Dec 15, 2015, 3:25:30 PM12/15/15
to Google API JavaScript Client
Hello,

If I understand well you are using the Google JavaScript client library. Have a look at this example which shows how to authenticate and load an Api at the same time (Section "Adding authentication support with OAuth 2.0").

https://cloud.google.com/appengine/docs/java/endpoints/consume_js

This works well with any number of apis, i.e. the apisToLoad variable can be set to any value greater than 2.

Hope this helps

Reply all
Reply to author
Forward
0 new messages