Skip to content

Instantly share code, notes, and snippets.

@j138
Created April 2, 2014 04:39
Show Gist options
  • Save j138/9928019 to your computer and use it in GitHub Desktop.
Save j138/9928019 to your computer and use it in GitHub Desktop.
imgur-tweetbot-custom-api.php
<?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($_FILES['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);
$ret = json_decode($json_returned, true);
echo json_encode(array('url' => $ret['data']['link']));
curl_close ($curl);
@mcskrzypczak
Copy link

Thank you for that little script, it works! Just a question. I provide my Client ID but when upload photo via Tweetbot it does not show up on my Imgur account. Any ideas why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment