1

我正在尝试让 twitter update_profile_image 使用 OAuth 工作。我使用 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();
  }

我一直试图解决这个问题,任何帮助将不胜感激。我与这个库没有任何关系,所以请随意推荐其他人。

4

1 回答 1

1

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

于 2010-04-30T21:33:15.977 回答