2011-03-12 37 views
2

我使用Oauth連接到Twitter,但會導致401錯誤。我在這裏做錯了什麼?Twitter和Oauth導致401錯誤

//config 
define('CONSUMER_KEY',""); 
define('CONSUMER_SECRET',""); 
define('OAUTH_TOKEN',"1U"); 
define('OAUTH_TOKEN_SECRET',""); 

require_once('twitteroauth/twitteroauth.php'); 

$connection = new TwitterOAuth (CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET); 

$connection->post('statuses/update', array('status' => 'testing')); 

$httpc = $connection->http_code; 
if($httpc == 200) { 
echo 'succesvol'; 
} else { 

echo $httpc; 
} 
+0

Twitter返回什麼錯誤信息? – abraham

回答

4

你得到一個401 (Not Authorised)錯誤時,你不提供正確的ConsumerKeyConsumerSecret值。

看看上面的代碼,您傳遞這兩個變量的空字符串值。除非你故意留下,否則你需要仔細檢查你的值。

對於我的應用程序,這是它們存在的地方。

(假設:您已經創建了一個Twitter應用@dev.twitter.com

enter image description here

祝您好運!

+6

+1大聲笑我想OP可能會找到領域感謝你的小箭頭 – ManseUK

+0

Tehehehehehehehehe –