Skip to content

Instantly share code, notes, and snippets.

@ssx
Created February 28, 2011 17:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssx/847682 to your computer and use it in GitHub Desktop.
Save ssx/847682 to your computer and use it in GitHub Desktop.
Single Account / Verify Credentials
<?php
// OAuth Examples: Twitter
// by Scott Wilcox <scott@dor.ky> http://dor.ky @dordotky
// https://dor.ky/oauth-examples/twitter
//
// This script verifies that the credentials you have are actually valid.
//
// First, require the OAuth library that we're going to use to handle all of the
// OAuth dirty work.
require "../library/EpiCurl.php";
require "../library/EpiOAuth.php";
require "../library/EpiTwitter.php";
define("CONSUMER_KEY","K8kq7COAxSZkgbwcsdyWDQ");
define("CONSUMER_SECRET","TQpyYbJrSHUHQHWKOIWKvMQ6um8CsgPgQAUVZ8RI");
define("OAUTH_TOKEN","194052389-K5sxAwEH5bjNiOlsmU7wtB7HqWIFdhGA9vGM79kO");
define("OAUTH_TOKEN_SECRET","XVPkIns0m4darfPxqoWWVho3UxCieAOdoZ5VhLZhuN4");
// Now try to make a call to account/verify_credentials to see if the tokens
// that we have are actually valid. If you get an error, re-check your tokens
// and try again. If everything works, you should see the script dump out a
// JSON user object
try {
// Create a new object to interact with the API
$twitterObject = new EpiTwitter(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET);
// Make a call to the API for verify_credentials API endpoint
$response = $twitterObject->get('/account/verify_credentials.json');
// Test to see we got a HTTP 200 code returned, we'll var_dump it out at
// this point, but you could display the users profile image
if ($response->code == 200) {
// Display the returned JSON in a pretty fashion along with the users
// profile image.
echo "<img src=\"".$response["profile_image_url"]."\" alt=\"".$response["name"]."\" /><br />";
echo "<pre>";
echo var_dump(json_decode($response->responseText));
echo "</pre>";
} else {
echo "Error: HTTP Code ".$response->code." was returned.";
}
} catch (Exception $error) {
// Something failed, this will output the error message from the API
echo "Error: ".$error->getMessage()."\n";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment