Change Twitter Profile Picture (Avatar) with Google Scripts
This Google Script updates the Twitter user’s profile image or avatar. Twitter asynchronously processes the uploaded file before updating the user’s profile image URL.
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');
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/image.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.1/account/update_profile_image.json', options);
}
Amit Agarwal
Google Developer Expert, Google Cloud Champion
Amit Agarwal is a Google Developer Expert in Google Workspace and Google Apps Script. He holds an engineering degree in Computer Science (I.I.T.) and is the first professional blogger in India.
Amit has developed several popular Google add-ons including Mail Merge for Gmail and Document Studio. Read more on Lifehacker and YourStory