Skip to content

Instantly share code, notes, and snippets.

@j138
Created April 2, 2014 04:05
Show Gist options
  • Save j138/9927766 to your computer and use it in GitHub Desktop.
Save j138/9927766 to your computer and use it in GitHub Desktop.
imgur-tweetbot-custom-api
<?php
// access and get api key
// chose :authorized_type -> Anonymus usage without user authorization
// https://api.imgur.com/oauth2/addclient
// plz input ur api_id
$client_id = 'plz-input-urapi-id';
if (!$_POST) exit('post plz');
$file = file_get_contents($_FILE['media']['tmp_name']);
$url = 'https://api.imgur.com/3/image.json';
$headers = array("Authorization: Client-ID $client_id");
$pvars = array('image' => base64_encode($file));
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL=> $url,
CURLOPT_TIMEOUT => 30,
CURLOPT_POST => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POSTFIELDS => $pvars
));
$json_returned = curl_exec($curl); // blank response
$ret = json_decode($json_returned, true);
echo json_encode(array('url' => $ret['data']['link']));
curl_close ($curl);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment