Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include_once "oauth-php/library/OAuthStore.php";
- include_once "oauth-php/library/OAuthRequester.php";
- define("IMGUR_CONSUMER_KEY", "xxx");
- define("IMGUR_CONSUMER_SECRET", "yyy");
- define("IMGUR_OAUTH_HOST","http://api.imgur.com");
- define("IMGUR_REQUEST_TOKEN_URL", IMGUR_OAUTH_HOST . "/oauth/request_token");
- define("IMGUR_AUTHORIZE_URL", IMGUR_OAUTH_HOST ."/oauth/authorize");
- define("IMGUR_ACCESS_TOKEN_URL", IMGUR_OAUTH_HOST ."/oauth/access_token");
- define("IMGUR_UPLOAD_URL", IMGUR_OAUTH_HOST ."/2/account/images");
- $options = array('consumer_key' => IMGUR_CONSUMER_KEY, 'consumer_secret' => IMGUR_CONSUMER_SECRET);
- OAuthStore::instance("2Leg",$options);
- try
- {
- $request = new OAuthRequester(IMGUR_REQUEST_TOKEN_URL, "POST");
- $result = $request->doRequest(0);
- parse_str($result['body'], $params);
- $filename = "image.jpg";
- $handle = fopen($filename, "r");
- $data = fread($handle, filesize($filename));
- // $data is file data
- $pvars = array('image' => base64_encode($data), 'key' => $params["oauth_token"]);
- $timeout = 30;
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, IMGUR_UPLOAD_URL);
- curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
- curl_setopt($curl, CURLOPT_POST, 1);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $pvars);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- //oauth_verifier
- $request_upload_2 = new OAuthRequester(IMGUR_UPLOAD_URL,"PUT",$params);
- $result_upload_2 = $request_upload_2->doRequest(0, $curl);
- }
- catch(OAuthException2 $e)
- {
- echo "Exception" . $e->getMessage();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement