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.

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

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了