Jump to content

update Twitter profile pic?


muppet77

Recommended Posts

i get a message saying i cannot be authorised - i have keys, tokens, passwords, users etc but do not know how to implement them or update this script.

 

any help for a super novice would be great!

 

<html><head><title>Title</title>
<?php
if (!isset($_POST['submit'])) { // if page is not submitted to itself
                                //echo the form
} else {

$username = $_POST["username"];
$password = $_POST["password"];
$image = $_POST["image"];

////// 
//////
////// If you are using file uploads from your form, use the following block
////// NOTE: this particular example code uses file uploads from the input form
//////
//////

$filename = $_FILES["image"]['name'];
$tmpfilename = $_FILES["image"]['tmp_name'];

$fileparts = explode(".", $filename);
/* get file extension */
$ext = $fileparts[count($fileparts) - 1];
$newfilename = substr($tmpfilename, 0, strlen($tmpfilename) - strlen($ext))  . "." .$ext;
//echo $newfilename;
/*
*  this next line creates a "corrected" file ending in .gif/.png/.jpg so 
*  the post headers are correct when CURL makes the request
*/
copy($tmpfilename, $newfilename);

////// 
//////
////// Else If you are using canned files local to your server,  use the following block
////// NOTE: you MUST use full path to image!
//////

//
// /* windows, notice FORWARD SLASHES */
// $newfilename = "c:/www/path/to/image.jpg";
//
//
// /* *nix */
// $newfilename = "/www/path/to/image.jpg";
//




// The twitter API address
$url = 'http://twitter.com/account/update_profile_image.xml';
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, "$url");
curl_setopt($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_HTTPHEADER, array('Expect:'));
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, array("image" => "@$newfilename"));
curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password");
$buffer = curl_exec($curl_handle);

curl_close($curl_handle);
       echo $buffer;


// if you want to delete the local temp image from uploading, uncomment this next line:
// unlink($newfilename);


}
?>



</head>
<body>

<form enctype="multipart/form-data" method="post" action="<?php echo $PHP_SELF;?>">
Username:<input type="text" size="12" maxlength="12"
name="username"><br />
Password:<input type="password" size="12" maxlength="36"
name="password"><br />
<input type="file" name="image">
<input type="submit" value="submit" name="submit"><br />
</form><br />

</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.