dongpo5207 2013-08-11 20:01
浏览 45
已采纳

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

This is my first time playing with an api and oauth and tumblr has a php client. I have downloaded and installed the client with 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?

I also know the process of oauth but I don't know how to actually implement it :/

  • 写回答

1条回答 默认 最新

  • doubeng3412 2013-08-12 00:04
    关注

    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. You can look at the OAuth part in Tumblr's Authentication documentation to get the correct endpoints.

    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 (e.g. request_token) use "http://www.tumblr.com". To be able to use the OAuth endpoints, you will just have to change the base 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:

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化