2011-11-20 29 views
0

我正在使用Abhraham的twitter API庫。「無法驗證你」來自twitter API的錯誤

我的index.php

<?php 
ob_start(); 
session_start(); 
require_once 'twitteroauth/twitteroauth.php'; 
require_once 'twitteroauth/OAuth.php'; 
define("CONSUMER_KEY", ""); 
define("CONSUMER_SECRET", ""); 
$to = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET); 
$tok = $to->getRequestToken("http://mydoamin.com/twitter/redirect.php"); 
$request_link = $to->getAuthorizeURL($tok); 
$_SESSION['oauth_access_token']= $tok['oauth_token']; 
$_SESSION['oauth_access_token_secret'] = $tok['oauth_token_secret']; 
header("Location: $request_link"); 
exit; 
?> 

我redirect.php

<?php 
ob_start(); 
session_start(); 
require_once 'twitteroauth/twitteroauth.php'; 
require_once 'twitteroauth/OAuth.php'; 
define("CONSUMER_KEY", ""); 
define("CONSUMER_SECRET", ""); 

$to=new TwitterOAuth(CONSUMER_KEY,CONSUMER_SECRET,$_SESSION['oauth_access_token'],$_SESSION['oauth_access_token_secret']); 
$content = $to->get('account/verify_credentials'); 
var_dump($content); 
?> 

但我不understant爲什麼我的redirect.php頁面上獲得"Could not authenticate you"

+0

您確認您的sesison處理正在保留在下一頁上嗎? – Scuzzy

+2

你真的想在這裏揭露你的鑰匙嗎? – vascowhite

+0

@iThink現在更改您的Twitter API密鑰。即使他們被編輯出來,也爲時已晚。它們位於編輯歷史記錄中,Google緩存中以及任何已打開此頁面的瀏覽器中。 – jdl

回答

0

我覺得這沒有按因爲不能直接將$tok放入getAuthrorizeURL()函數中:

$tok = $to->getRequestToken("http://mydoamin.com/twitter/redirect.php"); 
$request_link = $to->getAuthorizeURL($tok); 

您需要從$tok['oauth_token']提取令牌:

$tok = $to->getRequestToken("http://mydoamin.com/twitter/redirect.php"); 
$request_link = $to->getAuthorizeURL($tok['oauth_token']); 

讓我知道這是否修復它。

相關問題