2011-09-04 101 views
1

任何想法如何用圖像更新用戶的Twitter狀態 - 使用Twitter-Async類?通過Twitter與媒體更新Twitter狀態異步

這是我

$twitter = new Twitter(CONSUMER_KEY, CONSUMER_SECRET,$_SESSION['oauth_token'],$_SESSION['oauth_token_secret']); 
$array = array('media[]' => '@/img/1.jpg','status' => $status); 

$twitter->post('/statuses/update_with_media.json', $array); 

回答

1

與感謝@billythekid,我已經成功地做到這一點。這是你需要做的事情: 在EpiOAuth文件中查看這些函數,看看我添加了什麼,並在必要時進行修改。

EpiOAuth.php

//I have this on line 24 
    protected $mediaUrl  = 'https://upload.twitter.com'; 

//and altered getApiUrl() to include check for such (you may wish to make this a regex in keeping with the rest?) 
    private function getApiUrl($endpoint) 
    { 
    if(strpos($endpoint,"with_media") > 0) 
     return "{$this->mediaUrl}/{$this->apiVersion}{$endpoint}"; 
    elseif(preg_match('@^/(trends|search)[./]?(?=(json|daily|current|weekly))@', $endpoint)) 
     return "{$this->searchUrl}{$endpoint}"; 
    elseif(!empty($this->apiVersion)) 
     return "{$this->apiVersionedUrl}/{$this->apiVersion}{$endpoint}"; 
    else 
     return "{$this->apiUrl}{$endpoint}"; 
    } 

// add urldecode if post is multiPart (otherwise tweet is encoded) 
    protected function httpPost($url, $params = null, $isMultipart) 
    { 
    $this->addDefaultHeaders($url, $params['oauth']); 
    $ch = $this->curlInit($url); 
    curl_setopt($ch, CURLOPT_POST, 1); 
    // php's curl extension automatically sets the content type 
    // based on whether the params are in string or array form 
    if ($isMultipart) { 
     $params['request']['status'] = urldecode($params['request']['status']); 
    } 

    if($isMultipart) 
     curl_setopt($ch, CURLOPT_POSTFIELDS, $params['request']); 
    else 
     curl_setopt($ch, CURLOPT_POSTFIELDS, $this->buildHttpQueryRaw($params['request'])); 
    $resp = $this->executeCurl($ch); 
    $this->emptyHeaders(); 

    return $resp; 
    } 

後的圖像

// how to post image 
$twitter = new Twitter(CONSUMER_KEY, CONSUMER_SECRET,$_SESSION['oauth_token'],$_SESSION['oauth_token_secret']); 
$array = array('@media[]' => '@/img/1.jpg','status' => $status); 

$twitter->post('/statuses/update_with_media.json', $array); 
+0

我如何從一個網址,上傳圖片,如 「http://i.imgur.com/Wm4PM8A.png」 。 –