Guest User

Untitled

a guest
Jul 8th, 2015
92
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. error_reporting(0);
  3. $user = "";
  4. $pass = "";
  5. $client_id = "";
  6. $client_secret = "";
  7. $image = "http://s12.postimg.org/3sqadqhd9/aerosol.jpg";
  8.  
  9. function curl($url, $postdata, $token) {
  10.     $ch =  curl_init();
  11.  
  12.     curl_setopt( $ch, CURLOPT_URL, $url );
  13.     curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
  14.     curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
  15.     curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
  16.     curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0" );
  17.     curl_setopt( $ch, CURLOPT_POST, 1 );
  18.     curl_setopt( $ch, CURLOPT_POSTFIELDS, $postdata );
  19.     curl_setopt( $ch, CURLOPT_COOKIEJAR,  "cookieslogin.txt" );
  20.     curl_setopt( $ch, CURLOPT_COOKIEFILE, "cookieslogin.txt" );
  21.     curl_setopt( $ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer ".$token) );
  22.  
  23.     $result = curl_exec( $ch );
  24.     curl_close( $ch );
  25.     return $result;
  26. }
  27.  
  28. $login = curl("https://imgur.com/signin", "username=$user&password=$pass&remember=remember&submit=", "");
  29. if(preg_match("/account-user-name/", $login)) {
  30.     echo "Logged in. \n";
  31. } else {
  32.     die("Login failed! \n");
  33. }
  34. $getPin = curl("https://api.imgur.com/oauth2/authorize?client_id=".$client_id."&response_type=pin", "", "");
  35. if(preg_match("/An application would like to connect to your account/", $getPin)) {
  36.     preg_match("/name=\"allow\" value=\"(.*)\" /", $getPin, $allowid);
  37.     setcookie("authorize_token", $allowid[1], time(), "/", "api.imgur.com", 0, true);
  38.     $allow = curl("https://api.imgur.com/oauth2/authorize?client_id=".$client_id."&response_type=pin", "allow=".$allowid[1], "");
  39.     preg_match("/pin=(.*)\"/", $allow, $pin);
  40. } else {
  41.     preg_match("/pin=(.*)\"/", $getPin, $pin);
  42. }
  43. $token = curl("https://api.imgur.com/oauth2/token", "client_id=".$client_id."&client_secret=".$client_secret."&pin=".$pin[1]."&grant_type=pin", "");
  44. $json = json_decode($token, true);
  45. $upload = curl("https://api.imgur.com/3/upload", "image=".$image, $json["access_token"]);
  46. $json = json_decode($upload, true);
  47. if($json["data"]["link"]) {
  48.     echo $json["data"]["link"]."\n";
  49. } else {
  50.     echo $json["data"]["error"]."\n";
  51. }
RAW Paste Data