OAuth - 获取访问令牌

OAuth - getAccessToken Tumblr

这是我的代码:

<?php
session_start();

if ($_GET['oauth_verifier'] && $_GET['oauth_token'])
{
    $oauth = new OAuth(
        'wvo35DiIDRY5SMfA47OpDDDW958yWckPcs00gFwQdaGtk7e###',
        'LvX6zPEtNxZU4sO3BO0V7kkVxI7V0TB6CnSXfIFRKVUdTyQ###',
        $_SESSION['oauth_token'],
        $_SESSION['oauth_token_secret']
    );
    $oauth->setToken($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
    $accesToken = $oauth->getAccessToken('http://www.tumblr.com/oauth/access_token'); // ERROR LINE

    $oauth->setToken($accessToken["oauth_token"],$accessToken["oauth_token_secret"]);
    exit();
}

$oauth = new OAuth(
    'wvo35DiIDRY5SMfA47OpDDDW958yWckPcs00gFwQdaGtk7e###',
    'LvX6zPEtNxZU4sO3BO0V7kkVxI7V0TB6CnSXfIFRKVUdTyQ###',
    OAUTH_SIG_METHOD_HMACSHA1,
    OAUTH_AUTH_TYPE_URI
);

$requestToken = $oauth->getRequestToken('http://www.tumblr.com/oauth/request_token');

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

header("Location: https://www.tumblr.com/oauth/authorize?oauth_token={$requestToken['oauth_token']}");

我有错误:

Fatal error: Uncaught exception 'OAuthException' with message 'Invalid auth/bad request (got a 400, expected HTTP/1.1 20X or a redirect)' in

我该如何解决这个问题?

好的..我检查了一切,变量:

  • $_SESSION['oauth_token']
  • $_SESSION['oauth_token_secret']

是空的..因为我在变量名中犯了一个错误:

$requestToken = $oauth->getRequestToken('http://www.tumblr.com/oauth/request_token');

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

一开始我使用$requestToken,但接下来我使用$request_token。

谢谢,抱歉!