Created
June 6, 2011 05:36
-
-
Save aaronpearce/1009781 to your computer and use it in GitHub Desktop.
dAmntoken grabber using PHP
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 | |
// Set vars | |
$os = PHP_OS; | |
$cid= 21; | |
$csecret= "dba44bb59a5b303dd3d66a13e3cd4665"; | |
// OS Check for browser opening | |
if($os == "Darwin") { | |
exec("open 'https://www.deviantart.com/oauth2/draft15/authorize?client_id=".$cid."&redirect_uri=http://damnapp.com/apicode.php&response_type=code'"); | |
} elseif($os == "WINNT") { | |
exec("start 'https://www.deviantart.com/oauth2/draft15/authorize?client_id=".$cid."&redirect_uri=http://damnapp.com/apicode.php&response_type=code'"); | |
} elseif($os == "Linux") { | |
exec("browser 'https://www.deviantart.com/oauth2/draft15/authorize?client_id=".$cid."&redirect_uri=http://damnapp.com/apicode.php&response_type=code'"); | |
} else { | |
echo "Could not open your browser to the required URL. Please load the below one!\r\n"; | |
echo 'https://www.deviantart.com/oauth2/draft15/authorize?client_id=".$cid."&redirect_uri=http://damnapp.com/apicode.php&response_type=code'; | |
} | |
// Retreiving the code | |
echo "Enter the code:\r\n"; | |
$code = trim(fgets(STDIN)); | |
// Getting the access token. | |
$curl_handle=curl_init(); | |
curl_setopt($curl_handle,CURLOPT_URL,'https://www.deviantart.com/oauth2/draft15/token?client_id='.$cid.'&redirect_uri=http://damnapp.com//apicode.php&grant_type=authorization_code&client_secret='.$csecret.'&code='.$code); | |
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); | |
$buffer = curl_exec($curl_handle); | |
curl_close($curl_handle); | |
$bufferArr = json_decode($buffer); | |
$token= $bufferArr->access_token; | |
// Authtoken | |
$curl_handle2=curl_init(); | |
curl_setopt($curl_handle2,CURLOPT_URL,'https://www.deviantart.com/api/draft15/user/damntoken?access_token='.$token); | |
curl_setopt($curl_handle2, CURLOPT_RETURNTRANSFER, 1); | |
$buffer = curl_exec($curl_handle2); | |
curl_close($curl_handle2); | |
$authtoken = json_decode($buffer); | |
// Username | |
$curl_handle3=curl_init(); | |
curl_setopt($curl_handle3,CURLOPT_URL,'https://www.deviantart.com/api/draft15/user/whoami?access_token='.$token); | |
curl_setopt($curl_handle3, CURLOPT_RETURNTRANSFER, 1); | |
$buffer = curl_exec($curl_handle3); | |
curl_close($curl_handle3); | |
$username = json_decode($buffer); | |
echo "\r\n\r\nYou are " . $username . " and your authtoken is: " . $authtoken . ", while your access token for the API is: " . $token . "\r\n"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment