简体   繁体   English

使用tumblrs官方php客户端获取oauth令牌

[英]get oauth token with tumblrs official php client

This is my first time playing with an api and oauth and tumblr has a php client . 这是我第一次使用api和oauth,tumblr拥有php客户端 I have downloaded and installed the client with composer. 我已经下载并安装了Composer客户端。 This is the code they have to set up the client. 这是他们设置客户端的代码。

$client = new Tumblr\API\Client($consumerKey, $consumerSecret);
$client->setToken($token, $tokenSecret);

I know the consumer key and secret but how do I get the token and token secret with tumblrs php client? 我知道使用者密钥和机密,但是如何使用tumblrs php客户端获取令牌和令牌机密?

I also know the process of oauth but I don't know how to actually implement it :/ 我也知道oauth的过程,但是我不知道如何实际实现它:/

Just so we're in the same page, you can get the user's token and secret by going through the browser sign-in flow dance. 就像我们在同一个页面上一样,您可以通过浏览器登录流程来获取用户的令牌和密码。 Tumblr's flow is pretty much the same as Twitter's so you can use this as reference: Implementing Sign in with Twitter . Tumblr的流程与Twitter的流程几乎相同,因此您可以将其用作参考: 实现使用Twitter登录 You can look at the OAuth part in Tumblr's Authentication documentation to get the correct endpoints. 您可以查看Tumblr的身份验证文档中的OAuth部分,以获取正确的端点。

Note that Tumblr's PHP client that you linked to has the default base url set to "http://api.tumblr.com/" whereas the OAuth endpoints (eg request_token ) use "http://www.tumblr.com" . 请注意,您链接到的Tumblr的PHP客户端默认基本URL设置为"http://api.tumblr.com/"而OAuth端点(例如request_token )使用"http://www.tumblr.com" To be able to use the OAuth endpoints, you will just have to change the base url. 为了能够使用OAuth端点,您只需要更改基本URL。 Here's an example of the first step in the sign-in flow, getting a request token: 这是登录流程中第一步的示例,获取请求令牌:

// Requesting for http://www.tumblr.com/oauth/request_token

$client = new Tumblr\API\Client($consumerKey, $consumerSecret);
// Change the base url
$client->getRequestHandler()->setBaseUrl('http://www.tumblr.com/');
$req = $client->getRequestHandler()->request('POST', 'oauth/request_token', [
  'oauth_callback' => '...',
]);
// Get the result
$result = $req->body->__toString();

You should get this in $result : 您应该在$result得到它:

oauth_token=ulE1EuaZvJSN0qIKfQO5EFgcrxrOLJF0Cnm7VbLQqj66oF9nwt&oauth_token_secret=PLjC7s4JeIlgm53q7FKL1wqQkFoL0775JC6UkHKiepAQ6TxXxp&oauth_callback_confirmed=true

See this commit in Github for more info on how this was made possible. 有关如何实现此功能的更多信息,请参见Github中的提交

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM