2010-04-29 8 views
1

J'essaie d'obtenir l'utilisation de OAuth pour twitter update_profile_image. J'utilisais curl avec l'authentification régulière et tout fonctionnait bien, mais je suis passé à OAuth en utilisant this library, et maintenant tout sauf update_profile_image fonctionne.Mise à jour de l'image de profil Twitter à l'aide de OAuth

J'ai lu quelque chose à propos de twitter OAuth having problems with multipart data, mais c'était il y a un certain temps et the plugin is supposed to have dealt with that issue.

Mon authentification régulière travaillant avec le code boucle

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

Mon code actuel OAuth [je devais couper vers le bas, il ne faut pas regarder mineur pour les erreurs de syntaxe]

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

Je suis essayant de comprendre cela pendant un moment, toute aide serait grandement appréciée. Je ne suis aucunement lié à this library, alors n'hésitez pas à en recommander d'autres.

Répondre

1

La version de la bibliothèque que j'utilisais était obsolète. Une fois que j'ai mis à jour, j'ai dû faire face à quelques autres problèmes, y compris erreur 401 en raison d'un mauvais moment du serveur, et maintenant tout fonctionne bien. L'impression du $ response-> responseText aide beaucoup.

Questions connexes