2011-07-24 7 views
-1

私は自分のアプリケーションからユーザーのつぶやきを投稿しようとしています。私は新鮮に私はつぶやきには問題を投稿することができません、oauth_tokenとoauth_secretを取得するたびに、私は後でのためにそれらを保存し、つぶやきを投稿しようとした場合、しかし、私はエラーを取得:twitter oauth認証と投稿tweet does not working

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

ここで私は、スクリプトです最初にトークンを取得するために使用します。

<?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']; 

?> 

任意のアイデア:

<?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 
session_start(); 
require("config.php"); 
require_once("twitterOAuth.php"); 

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

と:

答えて

0

は(あなたのコードの第二部では)このコードを使用してみてください。このコードはあなたのために機能しますか?

1
/*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))