Last active
September 13, 2015 08:59
-
-
Save takaya030/ab4a556d707cc1c9c9dc to your computer and use it in GitHub Desktop.
Sample of using https://github.com/tumblr/tumblr.php on Laravel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class BlogController extends BaseController { | |
const consumerKey = 'Your Consumer Key'; | |
const consumerSecret = 'Your Consumer Secret'; | |
public function getIndex() | |
{ | |
$param = Input::get(); | |
if( array_key_exists('oauth_verifier', $param) ) | |
{ | |
$client = new Tumblr\API\Client( self::consumerKey, self::consumerSecret ); | |
$requestHandler = $client->getRequestHandler(); | |
$requestHandler->setBaseUrl('https://www.tumblr.com/'); | |
$client->setToken($param['oauth_token'], Session::get('oauth_token_secret')); | |
// get access token | |
$resp = $requestHandler->request('POST', 'oauth/access_token', array('oauth_verifier' => $param['oauth_verifier'])); | |
$out = $resp->body; | |
$data = array(); | |
parse_str($out, $data); | |
// tell the user where to go | |
$client->setToken($data['oauth_token'], $data['oauth_token_secret']); | |
// get dashboard | |
$client->getRequestHandler()->setBaseUrl('http://api.tumblr.com'); | |
dd( $client->getDashboardPosts() ); | |
} | |
else | |
{ | |
// debug print | |
dd($param); | |
} | |
} | |
public function getInfo() | |
{ | |
$client = new Tumblr\API\Client( self::consumerKey, self::consumerSecret ); | |
$requestHandler = $client->getRequestHandler(); | |
$requestHandler->setBaseUrl('https://www.tumblr.com/'); | |
// request token | |
$resp = $requestHandler->request('POST', 'oauth/request_token', array()); | |
// get oauth token | |
$out = $resp->body; | |
$data = array(); | |
parse_str($out, $data); | |
// for callback function (コールバック先で使用するため、セッションに保存) | |
Session::put('oauth_token_secret', $data['oauth_token_secret']); | |
// oauth_verifier | |
return Redirect::to('https://www.tumblr.com/oauth/authorize?oauth_token='.$data['oauth_token']); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment