Skip to content

Instantly share code, notes, and snippets.

@gregavola
Created July 10, 2014 00:34
Show Gist options
  • Save gregavola/25761bcea1b16861fd50 to your computer and use it in GitHub Desktop.
Save gregavola/25761bcea1b16861fd50 to your computer and use it in GitHub Desktop.
tumblrphp-quick-start
<?php
session_start();
require ("tumblrPHP.php");
$consumer = "XXXXXXX";
$secret = "XXXXXXXX";
$tumblr = new Tumblr($consumer, $secret, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
// The oauth_verfier is set back from Tumblr and is needed to obtain access tokens
$oauth_verifier = $_GET['oauth_verifier'];
// User the getAcessToken method and pass through the oauth_verifier to get tokens;
$token = $tumblr->getAccessToken($oauth_verifier);
// Set the session for the new access tokens, replacing the request tokens
$_SESSION['oauth_token'] = $token['oauth_token'];
$_SESSION['oauth_token_secret'] = $token['oauth_token_secret'];
// Create a new instance of the Tumblr Class with the Request Tokens that we just set at line 40 and 41
$tumblr = new Tumblr($consumer, $secret, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
// Grab the followers by using the oauth_get method.
$followers = $tumblr->oauth_get("/blog/BLOG_URL_GOES_HERE/followers");
print_r($followers);
?>
<?php
session_start();
require ("tumblrPHP.php");
// Enter your Consumer / Secret Key:
$consumer = "XXXXXXXXXX";
$secret = "XXXX";
// Create a new instance of the Tumblr Class with your Conumser and Secret when you create your app.
$tumblr = new Tumblr($consumer, $secret);
// Get the request tokens based on your consumer and secret and store them in $token
$token = $tumblr->getRequestToken();
// Set session of those request tokens so we can use them after the application passes back to your callback URL
$_SESSION['oauth_token'] = $token['oauth_token'];
$_SESSION['oauth_token_secret'] = $token['oauth_token_secret'];
// Grab the Authorize URL and pass through the variable of the oauth_token
$data = $tumblr->getAuthorizeURL($token['oauth_token']);
// The user will be directed to the "Allow Access" screen on Tumblr
header("Location: " . $data);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment