[英]Trouble using PHP Twitter libraries to send tweet
作為序言,我對PHP知之甚少。 但是,我不確定這是一個PHP問題,但可能更多的是我理解連接到Twitter的庫的問題。
我按照這里的教程http://140dev.com/twitter-api-programming-tutorials/hello-twitter-oauth-php/使用了Matt Harris的推特庫。 除了我從twitter獲得的鑰匙外,我沒有改變任何東西。
當我運行以下代碼時,我得到一個未經授權的錯誤代碼401:
$tweet_text = 'Hello Twitter';
print "Posting...\n";
$result = post_tweet($tweet_text);
print "Response code: " . $result . "\n";
function post_tweet($tweet_text) {
require_once('tmhoauth/tmhOAuth.php');
$connection = new tmhOAuth(array(
'consumer_key' => '******',
'consumer_secret' => '******',
'user_token' => '******',
'user_secret' => '******',
));
// Make the API call
$connection->request('POST',
$connection->url('1/statuses/update'),
array('status' => $tweet_text));
return $connection->response['code'];
}
?>
正如我之前所說,我使用的是twitter提供的密鑰。
我可以幫助我嘗試使用上面的庫在https://api.twitter.com/1/account/verify_credentials.json上測試twitter credientail驗證器嗎?
我也嘗試使用以下示例與此SO帖子中的TwitterOAuth庫使用基本oauth發送推文 :
<?php
require_once('twitteroauth.php');
$connection = new TwitterOAuth('app consumer key', 'app consumer secret', 'my access token', 'my access token secret');
$connection->post('statuses/update', array('status' => 'text to be tweeted'));
它不起作用; 但它確實將頁面轉發給了作者的github頁面!?!?
感謝您的任何幫助,您可以提供!
如果您確定密鑰是正確的,我建議您檢查一下twitter中的應用程序設置,以確保啟用了寫入模式。
在應用程序設置下,確保將應用程序類型訪問權限設置為
讀取,寫入和訪問直接消息
(或至少讀/寫)
那么也許嘗試再次生成訪問令牌?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.