public
Last active

Update Twitter avatar with Apps Script

  • Download Gist
gistfile1.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
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);
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.