Skip to content

Instantly share code, notes, and snippets.

@thom4parisot
Last active December 11, 2015 05:49
Show Gist options
  • Save thom4parisot/4555312 to your computer and use it in GitHub Desktop.
Save thom4parisot/4555312 to your computer and use it in GitHub Desktop.
Google Apps Scripts OAuth use case with Tumblr. Run the `startTumblrAuthorization` and follow the authorization workflow.
function getTumblrOAuthConfig_(){
// values available once an app is registered here: http://www.tumblr.com/oauth/apps
// registered app callback URL should be: https://script.google.com/macros
var consumer_key = "<OAuth Consumer Key>";
var consumer_secret = "<Secret Key>";
var oAuthConfig = UrlFetchApp.addOAuthService("Tumblr");
oAuthConfig.setAccessTokenUrl('http://www.tumblr.com/oauth/access_token');
oAuthConfig.setAuthorizationUrl('http://www.tumblr.com/oauth/authorize');
oAuthConfig.setRequestTokenUrl('http://www.tumblr.com/oauth/request_token');
oAuthConfig.setConsumerKey(consumer_key);
oAuthConfig.setConsumerSecret(consumer_secret);
return oAuthConfig;
}
function startTumblrAuthorization(){
var oAuthConfig = getTumblrOAuthConfig_();
var url = "http://api.tumblr.com/v2/user/info";
var options = {
"method": "GET",
"oAuthServiceName": "Tumblr",
"oAuthUseToken": "always"
};
var result = UrlFetchApp.fetch(url, options);
// If authorization is successful, on the next run, data are viewable in the "View > Logs…" menu
Logger.log(result.getContentText());
return oAuthConfig;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment