Skip to content
March 28, 2010 / ranacse05

Change Background image using Twitter API


I was playing with the twitter API and i found that they allow to change the background image and color scheme using API . So i tried to change those using php.

For this test i used the cURL and php . Here is the code

<?php

set_time_limit(0);
$twitterUser = $_REQUEST['username'] ;
$twitterPass = $_REQUEST['password'] ;

$link = "http://twitter.com/account/update_profile_background_image.xml"; // The URL to change the background image

$params = array(
			"image"=>"@$fullfilepath",
			"tile"=> $tile);

//$fullfilepath is NOT the http:// path , this is the file location . Its like /home/tmp/test.jpg . But if you want to use any file from the web you need to make a copy of that file in the server then use that .

// Tile is boolean , if you want to set the background tile then this should be 'true' , it took few minutes of me because i tried with 1 , then true but it needs string true so that is 'true' or "true" . 


twitter($link,$params); // Make the call with the parameters 

function twitter($link,$params){
	global $twitterUser; // This is the username
	global $twitterPass; // Password of the user

	$curl = curl_init();
	curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
	curl_setopt($curl, CURLOPT_HTTPHEADER, array('Expect:')); // Without the header you'll get 100 Error
	curl_setopt($curl, CURLOPT_URL, $link);
	curl_setopt($curl, CURLOPT_POST, 1);
	curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
	curl_setopt($curl, CURLOPT_USERPWD, "$twitterUser:$twitterPass");
	$resp = curl_exec($curl);
	curl_close($curl);
	
	return $resp;
	}

Thats it. Have fun. :)

About these ads

13 Comments

Leave a Comment
  1. nice work…keep going.

  2. web developments / Apr 12 2010 5:55 am

    thanks dude, I really need that.

  3. Dee / Jul 8 2010 8:37 pm

    Doesn’t work for me. =( Keeps sayin “Fatal error: Call to undefined function twitter()”

    • ranacse05 / Aug 6 2010 9:45 am

      check ur twitter function .

  4. marvin / Aug 16 2010 6:11 am

    another copy and paste tutorial.. this script is not working..
    account/update_profile_background_image is not functional until now..

    • ranacse05 / Nov 1 2010 4:35 pm

      @Marvin where do u live ? In earth its working nicely and if this tutorial copy & paste , can u tell me the original source ? I think that is ur site right ?

      So why they fuck u are reading my post ? Just fuck off .

  5. Gerri / Oct 3 2010 10:45 am

    Hi,

    Thanks for the info. I a currently working on a small project for one of my sites and am looking for a way of letting people change their twitter backgrounds using oAuth.Will the code you have above allow me to do that on a wordpress site?

  6. ranacse05 / Nov 1 2010 4:38 pm

    @Gerri

    Its it can be implemented with the oAuth , but u need to save the token and token secret on ur database to init one use users session .

    This script was using the basic auth and as that is already deprecated u cant just copy and paste the code .

  7. IMLYING2U / Oct 30 2011 6:08 am

    I know nothing about php scripts or twitter api’s but I was wondering can this be implemented on a blog? If so how?If not how do I implement this in a website, do I just add the script and that’s it?

  8. tanmaya / Nov 25 2011 8:41 pm

    Hi,
    can u just help me out,actually i have done twitter background change by using oauth , and it’s working fine but sometimes it’s just giving me fatal errors why……….

    • ranacse05 / Nov 25 2011 9:22 pm

      Sorry dont have any idea :(

  9. Reshman / May 21 2012 10:36 am

    super website

  10. Wilbur Rosenberg / Apr 10 2013 10:03 am

    There is certainly a lot to know about this topic. I really like all of the points you have made.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 29 other followers

%d bloggers like this: