繁体   English   中英

使用OAuth更新Twitter个人资料图片

[英]Update twitter profile image using OAuth

我正在尝试使用OAuth使twitter update_profile_image正常工作。 我使用的是带有常规身份验证的curl,并且一切正常,但是我使用此库切换到OAuth,现在除了update_profile_image之外的所有东西都可以正常工作。

我读到有关twitter OAuth的部分数据有问题的信息 ,但是那是前一阵子了, 该插件应该已经解决了该问题

我使用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);

我当前的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();
  }

我一直在努力弄清楚这一点,任何帮助将不胜感激。 我与该库没有任何关系,请随时推荐其他人。

我正在使用的库版本已过时。 更新后,我不得不处理其他一些问题,包括由于服务器时间错误而导致的401错误,现在一切正常。 打印$ response-> responseText有很大帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM