Update Profile Background Image of Twitter Account

From Twitter REST API v1.1, APP can update user’s Profile Background Image. The details of the API is here. First of all download tmhOAuth from github. To uodate background we will need oauth_token, oauth_token_secret. Here is an exampl to get those https://github.com/themattharris/tmhOAuth-examples/blob/master/auth.php

The background image for the profile, base64-encoded. Must be a valid GIF, JPG, or PNG image of less than 800 kilobytes in size. So here is the code

$tmhOAuth = new tmhOAuth(array(
  'consumer_key'    => $twitter_app_settings.key,
  'consumer_secret' => $twitter_app_settings.secret,
  'user_token'      => $oauth_token,
  'user_secret'     => $oauth_token_secret,
));

//lets say this code in upload.php. I am assuming that image file 
//is in same folder as upload.php. 
$file_name = '1391146912.png';
$file_link = getcwd() . "/$file_name";
$file_type = pathinfo($file_link, PATHINFO_EXTENSION);
 
$params = array(
    'image' => "@{$file_link};type={$file_type};filename={$file_name}",
);                              
$params['use'] = 'true';
 
$code = $tmhOAuth->request('POST', $tmhOAuth->url("1.1/account/update_profile_background_image.json"),
    $params,
    true, // use auth
    true  // multipart
);
if ($code == 200) 
    echo 'background image updated.';
else
    echo 'Something went worng!!';   

About Zakir Hyder

This entry was written by .

04. January 2013 by Zakir Hyder
Categories: PHP, Twitter | Tags: , | Comments

Comments

  1. […] Update Profile Background Image of Twitter Account January 4, 2013 3:11 PM From Twitter REST API v1.1, APP can update user’s Profile Background Image. The details of the API is here. First of all download tmhOAuth from github. To uodate background we will need oauth_token, oauth_token_secret. Here is an exampl to get … Continue reading → […]