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
https://forums.phpfreaks.com/topic/246013-update-twitter-profile-pic/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.