Search code examples
phpoauthtumblr

OAuth - getAccessToken Tumblr


This is My code:

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

And i have error:

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

How can I fix this?


Solution

  • Okey.. I checked everything, and varibles:

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

    was empty.. because I made a mistake in varibles name:

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

    At the beginning i use $requestToken, but next i use $request_token.

    Thanks and sorry!