验证后在Twitter上自动发布:获取无效的访问令牌错误

时间:2013-06-14 06:27:54

标签: twitter twitter-oauth

我需要在身份验证后自动在Twitter上发帖。

我的代码

<?php
session_start();
include("twitteroauth.php");


define('CONSUMER_KEY','zubLdCze6Erz9SVNIgG3w');
define('CONSUMER_SECRET','ZnZQ77bNnpBER2aSxTQGEXToAQODz9qEBSAXIdeYw');
define('OAUTH_CALLBACK','http://dev.pubs.positive-dedicated.net/Licensee/addPubEventWeekly.php');


/* Build TwitterOAuth object with client credentials. */
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);

/* Get temporary credentials. */
 $request_token = $connection->getRequestToken(OAUTH_CALLBACK);

/* Save temporary credentials to session. */
 $_SESSION['oauth_token'] = $token = $request_token['oauth_token'];
 $_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];


switch ($connection->http_code) {
  case 200:
    /* Build authorize URL and redirect user to Twitter. */
    $url = $connection->getAuthorizeURL($token);    
    header('Location: ' . $url); 
    break;
  default:
    /* Show notification if something went wrong. */
    echo 'Could not connect to Twitter. Refresh the page or try again later.';
}
?>

ksort($_SESSION);
                                    $tweet = new TwitterOAuth('zubLdCze6Erz9SVNIgG3w','ZnZQ77bNnpBER2aSxTQGEXToAQODz9qEBSAXIdeYw',$_SESSION['oauth_token'],$_SESSION['oauth_token_secret']);
                                    print_r($tweet);
                                    $account = $tweet->get('account/verify_credentials');

                                    $message = "This is an example twitter post using PHP";
                                    $postVal = $tweet->post('statuses/update', array('status' => $message));

但是我在这里得到“无效/过期的访问令牌”错误。

我已经将twittreauth.php库文件从1.0改为1.1到

public $host = "https://api.twitter.com/1.1/";

请建议如何解决此问题

0 个答案:

没有答案