Skip to content

Instantly share code, notes, and snippets.

@rcknr
Created August 9, 2012 17:43
Show Gist options
  • Save rcknr/3306363 to your computer and use it in GitHub Desktop.
Save rcknr/3306363 to your computer and use it in GitHub Desktop.
Update Twitter avatar with Apps Script
function oAuthConfig() {
var oAuthConfig = UrlFetchApp.addOAuthService("twitter");
oAuthConfig.setAccessTokenUrl("http://api.twitter.com/oauth/access_token");
oAuthConfig.setRequestTokenUrl("http://api.twitter.com/oauth/request_token");
oAuthConfig.setAuthorizationUrl("http://api.twitter.com/oauth/authorize");
// Register an app at https://dev.twitter.com/apps/new to get the following key and secret
oAuthConfig.setConsumerKey("PUT CONSUMER KEY HERE");
oAuthConfig.setConsumerSecret("PUT CONSUMER SECRET HERE");
}
function setProfileImage() {
oAuthConfig();
// This is a picture that will be set as Twitter avatar
var picture = UrlFetchApp.fetch("https://twitter.com/images/resources/twitter-bird-white-on-blue.png");
var encodedImage = Utilities.base64Encode(picture.getContent());
var options =
{
"method": "post",
"oAuthServiceName" : "twitter",
"oAuthUseToken" : "always",
"payload": { "image" : encodedImage, "skip_status": true}
};
var request = UrlFetchApp.fetch("http://api.twitter.com/1/account/update_profile_image.json", options);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment