shabith

imgur OAuth Error

Aug 4th, 2012
134
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.     include_once "oauth-php/library/OAuthStore.php";
  3.     include_once "oauth-php/library/OAuthRequester.php";
  4.    
  5.     define("IMGUR_CONSUMER_KEY", "xxx");
  6.     define("IMGUR_CONSUMER_SECRET", "yyy");
  7.    
  8.     define("IMGUR_OAUTH_HOST","http://api.imgur.com");
  9.     define("IMGUR_REQUEST_TOKEN_URL", IMGUR_OAUTH_HOST . "/oauth/request_token");
  10.     define("IMGUR_AUTHORIZE_URL", IMGUR_OAUTH_HOST ."/oauth/authorize");
  11.     define("IMGUR_ACCESS_TOKEN_URL", IMGUR_OAUTH_HOST ."/oauth/access_token");
  12.     define("IMGUR_UPLOAD_URL", IMGUR_OAUTH_HOST ."/2/account/images");
  13.  
  14.    
  15.     $options = array('consumer_key' => IMGUR_CONSUMER_KEY, 'consumer_secret' => IMGUR_CONSUMER_SECRET);
  16.    
  17.     OAuthStore::instance("2Leg",$options);
  18.    
  19.     try
  20.     {
  21.         $request = new OAuthRequester(IMGUR_REQUEST_TOKEN_URL, "POST");
  22.         $result = $request->doRequest(0);
  23.         parse_str($result['body'], $params);
  24.  
  25.         $filename = "image.jpg";
  26.         $handle = fopen($filename, "r");
  27.         $data = fread($handle, filesize($filename));
  28.        
  29.         // $data is file data
  30.         $pvars   = array('image' => base64_encode($data), 'key' => $params["oauth_token"]);
  31.         $timeout = 30;
  32.         $curl    = curl_init();
  33.    
  34.         curl_setopt($curl, CURLOPT_URL, IMGUR_UPLOAD_URL);
  35.         curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
  36.         curl_setopt($curl, CURLOPT_POST, 1);
  37.         curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  38.         curl_setopt($curl, CURLOPT_POSTFIELDS, $pvars);
  39.        
  40.         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  41.        
  42.    
  43.         //oauth_verifier
  44.        
  45.         $request_upload_2 = new OAuthRequester(IMGUR_UPLOAD_URL,"PUT",$params);
  46.         $result_upload_2 = $request_upload_2->doRequest(0, $curl);
  47.        
  48.     }
  49.     catch(OAuthException2 $e)
  50.     {
  51.          echo "Exception" . $e->getMessage();
  52.     }
RAW Paste Data