【问题标题】:Update Twitter status with media with Twitter Async使用 Twitter Async 使用媒体更新 Twitter 状态
【发布时间】:2014-02-27 19:54:38
【问题描述】:

知道如何用图片更新用户的 Twitter 状态 - 使用 Twitter-Async 类吗?

这就是我所拥有的

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

【问题讨论】:

    标签: php twitter


    【解决方案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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多