Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(0);
- $user = "";
- $pass = "";
- $client_id = "";
- $client_secret = "";
- $image = "http://s12.postimg.org/3sqadqhd9/aerosol.jpg";
- function curl($url, $postdata, $token) {
- $ch = curl_init();
- curl_setopt( $ch, CURLOPT_URL, $url );
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
- curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
- curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
- curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0" );
- curl_setopt( $ch, CURLOPT_POST, 1 );
- curl_setopt( $ch, CURLOPT_POSTFIELDS, $postdata );
- curl_setopt( $ch, CURLOPT_COOKIEJAR, "cookieslogin.txt" );
- curl_setopt( $ch, CURLOPT_COOKIEFILE, "cookieslogin.txt" );
- curl_setopt( $ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer ".$token) );
- $result = curl_exec( $ch );
- curl_close( $ch );
- return $result;
- }
- $login = curl("https://imgur.com/signin", "username=$user&password=$pass&remember=remember&submit=", "");
- if(preg_match("/account-user-name/", $login)) {
- echo "Logged in. \n";
- } else {
- die("Login failed! \n");
- }
- $getPin = curl("https://api.imgur.com/oauth2/authorize?client_id=".$client_id."&response_type=pin", "", "");
- if(preg_match("/An application would like to connect to your account/", $getPin)) {
- preg_match("/name=\"allow\" value=\"(.*)\" /", $getPin, $allowid);
- setcookie("authorize_token", $allowid[1], time(), "/", "api.imgur.com", 0, true);
- $allow = curl("https://api.imgur.com/oauth2/authorize?client_id=".$client_id."&response_type=pin", "allow=".$allowid[1], "");
- preg_match("/pin=(.*)\"/", $allow, $pin);
- } else {
- preg_match("/pin=(.*)\"/", $getPin, $pin);
- }
- $token = curl("https://api.imgur.com/oauth2/token", "client_id=".$client_id."&client_secret=".$client_secret."&pin=".$pin[1]."&grant_type=pin", "");
- $json = json_decode($token, true);
- $upload = curl("https://api.imgur.com/3/upload", "image=".$image, $json["access_token"]);
- $json = json_decode($upload, true);
- if($json["data"]["link"]) {
- echo $json["data"]["link"]."\n";
- } else {
- echo $json["data"]["error"]."\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment