twitter oauth 身份验证和发布推文不起作用

发布于 2024-11-25 19:24:20 字数 1989 浏览 2 评论 0原文

所以我试图通过我的应用程序发布用户的推文。每当我新获得 oauth_token 和 oauth_secret 时,我都可以毫无问题地发布推文,但是,如果我尝试保存它们以供稍后使用,然后发布推文,则会收到错误:

    object(stdClass)#5 (2) {
     ["error"]=>
      string(27) "Could not authenticate you."
       ["request"]=>
      string(23) "/1/statuses/update.json"
    }

这是我最初用于获取令牌的脚本:

<?php

require("config.php");
require("twitterOAuth.php");
session_start();

         if(!empty($_GET['oauth_verifier']) && !empty($_SESSION['oauth_token']) &&                                          !empty($_SESSION['oauth_token_secret'])){
    // We've got everything we need
} else {
    // Something's missing, go back to square 1
    //header('Location: new_index.php');
}

// TwitterOAuth instance, with two new parameters we got in twitter_login.php
$twitteroauth = new TwitterOAuth($consumer_key, $consumer_secret, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
// Let's request the access token

$oauth_token = $_SESSION['oauth_token'];
$oauth_secret = $_SESSION['oauth_token_secret'];

$access_token = $twitteroauth->getAccessToken($_GET['oauth_verifier']);

//post tweet
$result = $twitteroauth->post('statuses/update', array('status' => 'asd '));


// Save it in a session var
$_SESSION['access_token'] = $access_token;
// Let's get the user's info
$user_info = $twitteroauth->get('account/verify_credentials');
?>

这是我尝试使用令牌发送推文的脚本:

<?php
require("config.php");
require_once('twitterOAuth.php');
$oAuthToken     = $argv[1];
$oAuthSecret    = $argv[2];
$message = $argv[3];
$post_id = $argv[4];

// create a new instance
$tweet = new TwitterOAuth($consumerKey, $consumerSecret, "$oAuthToken", "$oAuthSecret");

//send a tweet
$result = $tweet->post('statuses/update', $message);//array('status' => "$message"));
$tweet_id = $result['id_str'];

?>

有什么想法吗?我真的需要一些帮助。昨晚它工作得很好,现在突然它根本不起作用:/

令牌是否会过期并且在它们不是会话变量后不起作用?

So I'm trying to post tweets of a user through my application. Whenever I freshly get the oauth_token and oauth_secret, I can post a tweet no problem, However, if I try to save them for later and then post a tweet, I get the error:

    object(stdClass)#5 (2) {
     ["error"]=>
      string(27) "Could not authenticate you."
       ["request"]=>
      string(23) "/1/statuses/update.json"
    }

Here is the script I use to get the tokens initially:

<?php

require("config.php");
require("twitterOAuth.php");
session_start();

         if(!empty($_GET['oauth_verifier']) && !empty($_SESSION['oauth_token']) &&                                          !empty($_SESSION['oauth_token_secret'])){
    // We've got everything we need
} else {
    // Something's missing, go back to square 1
    //header('Location: new_index.php');
}

// TwitterOAuth instance, with two new parameters we got in twitter_login.php
$twitteroauth = new TwitterOAuth($consumer_key, $consumer_secret, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
// Let's request the access token

$oauth_token = $_SESSION['oauth_token'];
$oauth_secret = $_SESSION['oauth_token_secret'];

$access_token = $twitteroauth->getAccessToken($_GET['oauth_verifier']);

//post tweet
$result = $twitteroauth->post('statuses/update', array('status' => 'asd '));


// Save it in a session var
$_SESSION['access_token'] = $access_token;
// Let's get the user's info
$user_info = $twitteroauth->get('account/verify_credentials');
?>

And here is the script where I just try to tweet it using the tokens:

<?php
require("config.php");
require_once('twitterOAuth.php');
$oAuthToken     = $argv[1];
$oAuthSecret    = $argv[2];
$message = $argv[3];
$post_id = $argv[4];

// create a new instance
$tweet = new TwitterOAuth($consumerKey, $consumerSecret, "$oAuthToken", "$oAuthSecret");

//send a tweet
$result = $tweet->post('statuses/update', $message);//array('status' => "$message"));
$tweet_id = $result['id_str'];

?>

Any ideas? I could really use some help here. It worked fine last night and now all the sudden it's not working at all :/

Could the tokens expire and not work after they're not session variables?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烟沫凡尘 2024-12-02 19:24:20
/*Try this one it will work proper*/
session_start();
require("config.php");
require_once("twitterOAuth.php");

$access_token = $_SESSION['access_token'];//which you got from callback

/* Create a TwitterOauth object with consumer/user tokens. */
$tweet      = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);

$tweet->post('direct_messages/new', array('text' => $messageBody, 'screen_name' => $screenName))
/*Try this one it will work proper*/
session_start();
require("config.php");
require_once("twitterOAuth.php");

$access_token = $_SESSION['access_token'];//which you got from callback

/* Create a TwitterOauth object with consumer/user tokens. */
$tweet      = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);

$tweet->post('direct_messages/new', array('text' => $messageBody, 'screen_name' => $screenName))
葮薆情 2024-12-02 19:24:20

尝试使用此代码(在代码的第二部分):

<?php
session_start();
require("config.php");
require_once("twitterOAuth.php");

$oAuthToken = $_SESSION['oauth_token'];
$oAuthSecret = $_SESSION['oauth_token_secret'];

等等。这段代码对你有用吗?

Try to use this code (in the second part of your code):

<?php
session_start();
require("config.php");
require_once("twitterOAuth.php");

$oAuthToken = $_SESSION['oauth_token'];
$oAuthSecret = $_SESSION['oauth_token_secret'];

and so on. Does this code work for you?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文