2013-06-23 22 views
0

我希望能夠以我的用戶的名義向微博發佈推文,他們希望在我的網站上以推文的形式分享他們的帖子。我正在使用James Mallison的精彩TwitterAPIExchange類,並試圖使用PHP在twitter上發佈。班級被發現here爲什麼我的方法使用新的Twitter API不好?

我想通過以下方式來使用它:

 /** Set access tokens here - see: https://dev.twitter.com/apps/ **/ 
     $settings = array(
      'oauth_access_token' => $core->getOauthAccessToken(), 
      'oauth_access_token_secret' => $core->getOauthAccessTokenSecret(), 
      'consumer_key' => $core->getTwitterConsumerKey(), 
      'consumer_secret' => $core->getTwitterConsumerSecret() 
     );    
     $url = 'https://api.twitter.com/1.1/statuses/update.json'; 
     $requestMethod = 'POST';    
     $stripped_question = "See my reply to \"$stripped_question\""; 
     $stripped_response = $stripped_response; 
     $message = $stripped_question.$stripped_response; 
     /*$postfields = array(
      'status' => rawurlencode(rawurlencode($message)) 
     );*/    
     $postfields = array(
     CURLOPT_HTTPHEADER => array("https://api.twitter.com/oauth/authorize"), 
     CURLOPT_HEADER => false, 
     CURLOPT_URL => $core->getHomeUrl(), 
     CURLOPT_POST => true, 
     CURLOPT_POSTFIELDS => 'status=' . rawurlencode(rawurlencode($status)), 
     CURLOPT_RETURNTRANSFER => true, 
     CURLOPT_VERBOSE => true, 
     CURLOPT_SSL_VERIFYPEER => false 
     ); 
     /** Perform the request and echo the response **/ 
     $twitter = new TwitterAPIExchange($settings); 
     echo "<!--".var_dump($twitter->buildOauth($url, $requestMethod) 
      ->setPostfields($postfields) 
      ->performRequest())."-->";    

然而,什麼是錯的,我得到以下錯誤:

string(63) "{"errors":[{"message":"Could not authenticate you","code":32}]}" 

所以,我的問題是:我怎麼能以我的網站用戶的名義向推特發佈推文?爲什麼Twitter無法驗證用戶?我檢查了數據,一切似乎都是正確的,所以我認爲問題在於我的帖子中的第二個代碼。非常感謝您的答覆。

+0

嘿拉霍斯,你有這個工作嗎? – Jimbo

回答

0

一些小的檢查

  1. 你重新訪問令牌?
  2. 你有在應用程序的寫權限?

第一個爲我工作。

+0

訪問級別是讀取,寫入和直接消息。我重新創建了訪問令牌。所以你的回答有一些很好的建議,但不幸的是這並不能解決我的問題。 –

相關問題