1

这里我需要在认证后自动在 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/";

请建议如何解决这个问题

4

0 回答 0