问题
I am using the below HTTP request to retrieve data from my associated YouTube channel.
https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel%3D%3D{MY_ASSOCIATED_CHANNEL_ID}&start-date=2016-08-01&end-date=2016-08-31&metrics=views&dimensions=video&filters=video%3D%3D{MY_VIDEO_ID}&max-results=10&sort=-views& access_token= {MY_ACCESS TOKEN}
I am using google spreadsheet app script to process the above request.
Could you please help me to setup an additional function which will refresh my access token before run the above function (I already have a REFRESH TOKEN)
Thanks,
Aneesh
回答1:
You can check on this GitHub tutorial how to refresh the tokens when they expire.
OAuth2 for Apps Script is a library for Google Apps Script that provides the ability to create and authorize OAuth2 tokens as well as refresh them when they expire. This library uses Apps Script's new StateTokenBuilder and
/usercallback
endpoint to handle the redirects.
For this library (and the Apps Script functionality in general) the URL will always be in the following format:
https://script.google.com/macros/d/{SCRIPT ID}/usercallback
Where {SCRIPT ID}
is the ID of the script that is using this library. You can find your script's ID in the Apps Script code editor by clicking on the menu item "File > Project properties".
To do this, please follow the steps in the link provided above. Hope this helps!
来源:https://stackoverflow.com/questions/39635962/google-spreadsheet-app-script-to-refresh-the-access-token