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 is a web geek, solo entrepreneur and loves making things on the Internet. Google recently awarded him the Google Developer Expert and Google Cloud Champion title for his work on Google Workspace and Google Apps Script.

Awards & Recognition

Google Developer Expert

Google Developer Expert

Google awarded us the Developer Expert title recogizing our work in Workspace

ProductHunt Golden Kitty

ProductHunt Golden Kitty

Our Gmail tool won the Lifehack of the Year award at ProductHunt Golden Kitty Awards

Microsoft MVP Alumni

Microsoft MVP Alumni

Microsoft awarded us the Most Valuable Professional title for 5 years in a row

Google Cloud Champion

Google Cloud Champion

Google awarded us the Champion Innovator award for technical expertise

Want to stay up to date?
Sign up for our email newsletter.

We will never send any spam emails. Promise 🫶🏻