Reputation: 95
I am trying to implement the imgur api in PHP, but I cannot get it to authenticate. Im using file_get_contents to get the results from the api, and ive set the header to contain my Client-Id.
$opts = array(
'http'=>array(
'method'=>"POST",
'header'=>"Authorization: Client-ID CLIENT_ID"
)
);
$context = stream_context_create($opts);
$file = file_get_contents('https://api.imgur.com/3/image/$get', false, $context);
echo $file;
But it still says "Authentication required" and returns the status of 401. Any ideas where I am going wrong?
Upvotes: 1
Views: 1702
Reputation: 16084
Have you registered your application? Why don't you try with a cURL request?
// Get cURL resource
$curl = curl_init();
// Set some options (including authentication header)
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'IMGUR_API_URL',
CURLOPT_HTTPHEADER => array('Authorization: Client-ID CLIENT_ID')
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
// Close request to clear up some resources
curl_close($curl);
Some hostings don't allow remote file access with file_get_contents()
Upvotes: 1