我正在使用twitteroauth库发布推文。这是我的代码
require("application/libraries/twitteroauth.php");
$twitteroauth = new TwitterOAuth(TW_KEY, TW_SECRET);
$request_token = $twitteroauth->getRequestToken();
print_r($request_token);
$tweet = new TwitterOAuth(TW_KEY, TW_SECRET, $request_token['oauth_token'], $request_token['oauth_token_secret']);
// the message
$message = "This is an example twitter post using PHP";
// send to twitter
$msg = $tweet->post('statuses/update', array('status' => $message));
print_r($msg); die;
但每次我收到错误消息
stdClass Object(
[errors] => Array(
[0] => stdClass Object
(
[message] => Invalid or expired token
[code] => 89
)
)
请求令牌已成功生成。我解决了我的问题。请帮帮我。
答案 0 :(得分:0)
如果您在Developer Twitter API Panel中登录,您将获得4个参数..即消费者密钥,消费者密钥,oAuth Token和oAuth Secret。只需从面板中复制它并将其粘贴到您的PHP代码上就像这样......
$consumerKey = 'LFrw******gQtXopxeQ';
$consumerSecret = '2rM0R*********aj8GXik4w';
$oAuthToken = '1127*********wcjnl9dNsVtTSb';
$oAuthSecret = '4fM**********TB52rwpnP6kyh';
之后只是打个电话......
require_once('twitteroauth.php');
$tweet = new TwitterOAuth($consumerKey, $consumerSecret, $oAuthToken, $oAuthSecret);
$tweet->get('account/verify_credentials');
$message = "This is the first tweet from Shankar ;)"; // I have added a message here
$tweet->post('statuses/update', array('status' => $message)); // Will do.. !
答案 1 :(得分:0)
默认的Twitter App权限集仅限只读。您需要更新Twitter应用程序读取和写入权限。