2010-04-29 121 views
1

我試圖讓twitter update_profile_image使用OAuth工作。我正在使用捲曲與定期身份驗證,一切工作正常,但我切換到OAuth使用this library,現在除update_profile_image之外的所有工作。使用OAuth更新twitter個人資料圖片

我讀了一些關於twitter OAuth having problems with multipart data,但那是前一陣子和the plugin is supposed to have dealt with that issue

我的工作,捲曲代碼的常規認證

$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(); 
    } 

我一直試圖找出一段時間,任何幫助將不勝感激。我不以任何方式綁定到this library,所以隨意推薦其他人。

回答

1

我使用的庫的版本已過時。一旦我更新了,我不得不處理其他一些問題,包括由於服務器時間錯誤導致的401錯誤,現在一切正常。打印出$ response-> responseText幫助很大。

相關問題