[英]Update twitter profile image using OAuth
I'm trying to get twitter update_profile_image to work using OAuth. 我正在尝试使用OAuth使twitter update_profile_image正常工作。 I was using curl with regular authentication and everything was working fine, but I switched to OAuth using this library , and now everything except update_profile_image works. 我使用的是带有常规身份验证的curl,并且一切正常,但是我使用此库切换到OAuth,现在除了update_profile_image之外的所有东西都可以正常工作。
I read something about twitter OAuth having problems with multipart data , but that was a while ago and the plugin is supposed to have dealt with that issue . 我读到有关twitter OAuth的部分数据有问题的信息 ,但是那是前一阵子了, 该插件应该已经解决了该问题 。
My working regular authentication with curl code 我使用curl代码进行常规身份验证
$url = 'http://api.twitter.com/1/account/update_profile_image.xml';
$uname = $_POST['username'];
$pword = $_POST['password'];
$img_path = 'xxx';
$userpwd = $uname . ':' . $pword;
$img_post = array('image' => '@' . $img_path . ';type=image/jpeg',
'tile' => 'true');
$format = 'xml'; //alternative: json
$message = 'Test update with a random num'.rand();
$opts = array(CURLOPT_URL => $url,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $img_post,
CURLOPT_HTTPAUTH => CURLAUTH_ANY,
CURLOPT_USERPWD => $userpwd,
CURLOPT_HTTPHEADER => array('Expect:'),
CURLINFO_HEADER_OUT => true);
$ch = curl_init();
curl_setopt_array($ch, $opts);
$response = curl_exec($ch);
$err = curl_error($ch);
$info = curl_getinfo($ch);
curl_close($ch);
My current OAuth code [I had to cut it down, so do not minor look for syntax errors] 我当前的OAuth代码[我不得不将其缩减,因此请不要小看语法错误]
include 'EpiCurl.php';
include 'EpiOAuth.php';
include 'EpiTwitter.php';
include 'secret.php';
$twitterObj = new EpiTwitter($consumer_key, $consumer_secret);
$twitterObj->setToken($_GET['oauth_token']);
$token = $twitterObj->getAccessToken();
$twitterObj->setToken($token->oauth_token, $token->oauth_token_secret);
try{
$img_path = 'xxx';
//$twitterObj->post_accountUpdate_profile_image(array('@image' => "@".$img_path));
$twitterObj->post('/account/update_profile_image.json', array('@image' => "@".$img_path));
$twitterObj->post_statusesUpdate(array('status' => 'This is my new status:'.rand())); //This works
$twitterInfo= $twitterObj->get_accountVerify_credentials();
echo $twitterInfo->responseText;
}catch(Exception $e){
echo $e->getMessage();
}
I've been trying to figure this out for a while, ANY help would be greatly appreciated. 我一直在努力弄清楚这一点,任何帮助将不胜感激。 I'm not in any way tied to this library , so feel free to recommend others. 我与该库没有任何关系,请随时推荐其他人。
The version of the library I was using was outdated. 我正在使用的库版本已过时。 Once I updated, I had to deal with a couple of other issues including 401 error due to a wrong server time, and now everything works fine. 更新后,我不得不处理其他一些问题,包括由于服务器时间错误而导致的401错误,现在一切正常。 Printing out the $response->responseText helps a lot. 打印$ response-> responseText有很大帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.