我没有设置会话正确,所以我是用我的实际与秘密的,而不是我的访问令牌请求令牌:P
if(empty($_GET["oauth_token"])) {
$_SESSION["token_secret"] = $oauthTokenSecret;
$_SESSION["oauth_token"] = $oauth_token;
echo '<script>window.location="'.$auth_url.'";</script>';
}
else {
$oauth_token->key = urldecode($_GET["oauth_token"]);
$oauth_token->secret = $_SESSION["token_secret"];
echo "<Br>";
echo "<Br> FIRST OAUTH TOKEN: ";
echo $oauth_token->key;
echo "<Br>";
echo "<Br> FIRST OAUTH TOKEN SECRET: ";
echo $oauth_token->secret;
print_r($_SESSION);
echo "<Br>";
echo "<Br>";
// GET https://www.google.com/accounts/OAuthGetAccessToken
$req = OAuthRequest::from_consumer_and_token($consumer, $oauth_token, 'GET',
$token_endpoint.'OAuthGetAccessToken', array('oauth_verifier' => $_GET['oauth_verifier']));
$req->sign_request($sig_method, $consumer, $oauth_token, $privKey);
print_r($req);
$response = send_signed_request('GET', $token_endpoint.'OAuthGetAccessToken', array($req->to_header()));
@Rafal - 我将确保你获得2单独的令牌(一个用于初始请求,另一个用于访问)。另外需要注意的是,使用新的令牌/密钥重新生成新签名非常重要,因为如果保持相同,它会返回“无效签名”。
由于在此过程中需要重定向,因此必须将初始令牌密码保留在SESSION变量中。用户返回到应用程序后,URL中将返回oauth_token,但令牌密钥不会。您必须将其存储在往返完成后可访问的变量中。
如果你想在会话中存储整个的oauth_token对象确保你实例化对象之前,你的“在session_start()”
$oauth_token = new OAuthToken($oauthToken, $oauthTokenSecret);
session_start();
否则,当你重新打印,您将收到一个“完全的对象”警告从SESSION收到的令牌。我在这个项目上花了很长时间,并且深入参与了OAuth。请随时问我任何问题,拉法尔。
我得到完全相同的错误(Google Analytics API除外)。有什么建议么? – 2011-05-27 15:27:59