¿Cómo obtengo access_token del cliente php oficial de tumblr?

I've followed the directions posted in esta pregunta de stackoverflow, but I am stuck.

I am using tumblr/tumblr.php from Github (the official "PHP client for the tumblr API").

I am also following directions aquí (which are actually for twitter), but those directions aren't tailored for the git library I am using.

I have a valid consumer key and secret.

From those I make a request and get oauth_token and oauth_token_secret like so:

$client = new Tumblr\API\Client($consumerKey,$consumerSecret);
$req = $client->getRequestHandler()->request('POST', 'oauth/request_token', [
  'oauth_callback' => '...',
// Get the result
$result = $req->body->__toString();
print_r( $result );

Lo que me da:


Then I send the user to the http://www.tumblr.com/oauth/authorize?oauth_token=2C6f...MqSF, so they can allow access for the app. This redirects to: ...?oauth_token=2C6f...MqSF&oauth_verifier=nvjl...GtEa#_=_

And now in the final step I believe I am supposed to convert my request token to an access token. Is that right? I am doing something wrong:

$client = new Tumblr\API\Client($consumerKey,$consumerSecret);
$req = $client->getRequestHandler()->request('POST', 'oauth/access_token', [
  'oauth_token' => '2C6f...MqSF',
  'oauth_verifier' => 'nvjl...GtEa'
// Get the result
$result = $req->body->__toString();
print_r( $result );

because I get responses like this one:

oauth_signature [AqbbYs0XSZ7plqB0V3UQ6O6SCVI=] does not match expected value [0XwhYMWswlRWgcr6WeA7/RrwrhA=]

What is wrong with my last step?

I am not sure if I should even be sending oauth_verifier with the request. Is #_=_ se supone que es parte de oauth_verifier? I wouldn't think so. I get signature errors for all the variations Ive tried.

Without the token and tokenSecret I can't make certain calls to the API. I get unauthorized 403 responses. Same when I use the token and token_secret from the second step. I'm pretty sure I need a new token/secret pair.

preguntado el 27 de noviembre de 13 a las 06:11

1 Respuestas

You're pretty close, you just are passing the oauth_token incorrectly in the last step, and skipping out on oauth_token_secret altogeter.

I've compiled this working code (which you can also now find posted on the Wiki at https://github.com/tumblr/tumblr.php/wiki/Authentication):



// some variables that will be pretttty useful
$consumerKey = '<your consumer key>';
$consumerSecret = 'your consumer secret>';
$client = new Tumblr\API\Client($consumerKey, $consumerSecret);
$requestHandler = $client->getRequestHandler();

// start the old gal up
$resp = $requestHandler->request('POST', 'oauth/request_token', array());

// get the oauth_token
$out = $result = $resp->body;
$data = array();
parse_str($out, $data);

// tell the user where to go
echo 'https://www.tumblr.com/oauth/authorize?oauth_token=' . $data['oauth_token'];
$client->setToken($data['oauth_token'], $data['oauth_token_secret']);

// get the verifier
echo "\noauth_verifier: ";
$handle = fopen('php://stdin', 'r');
$line = fgets($handle);

// exchange the verifier for the keys
$verifier = trim($line);
$resp = $requestHandler->request('POST', 'oauth/access_token', array('oauth_verifier' => $verifier));
$out = $result = $resp->body;
$data = array();
parse_str($out, $data);

// and print out our new keys
$token = $data['oauth_token'];
$secret = $data['oauth_token_secret'];
echo "\ntoken: " . $token . "\nsecret: " . $secret;

// and prove we're in the money
$client = new Tumblr\API\Client($consumerKey, $consumerSecret, $token, $secret);
$info = $client->getUserInfo();
echo "\ncongrats " . $info->user->name . "!\n";

respondido 27 nov., 13:15

Where do you get vendor/autoload.php? There is no such file in the Tumblr API. - CaimánCarver

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.