简体   繁体   English

IMGUR API-权限被拒绝

[英]IMGUR API - Permission Denied

I am using the IMGUR API and I get the following error 我正在使用IMGUR API,但出现以下错误

Warning: file_get_contents( https://api.imgur.com/3/album/f0J59/images ): failed to open stream: HTTP request failed! 警告:file_get_contents( https://api.imgur.com/3/album/f0J59/images ):无法打开流:HTTP请求失败! HTTP/1.1 403 Permission Denied in C:\\wamp\\www\\reddit_cards\\imgur_test.php on line 12 第12行的C:\\ wamp \\ www \\ reddit_cards \\ imgur_test.php中的HTTP / 1.1 403权限被拒绝

$opts = array(
    'http'=>array(
    'method'=>"POST",
    'header'=>"Authorization: Client-ID XXXXX"
    )
 );

$context = stream_context_create($opts);

 $file = file_get_contents('https://api.imgur.com/3/album/f0J59/images', false, $context);
 echo $file;

Check out this script I created few weeks back for uploading image to Imgur. 看看我几周前创建的脚本,用于将图像上传到Imgur。

Imgur.php Imgur.php

  <form enctype="multipart/form-data" method="post" action="imgur.php">
  Choose your file here:
  <input name="file" type="file"/>
  <input type="submit" value="Upload It"/>
 </form>

 if(isset($_FILES['file']))
 {
$filename = $_FILES['file']['tmp_name'];
$handle = fopen($filename, "r");
$data = fread($handle, filesize($filename));
print_r(imgur($data));
}
else
{
echo "Nothing Done";
}

function imgur($data)
{
$key = "IMGUR KEY";
$pvars   = array('image' => base64_encode($data), 'key' => $key);
$timeout = 30;
$curl    = curl_init();

curl_setopt($curl, CURLOPT_URL, 'http://api.imgur.com/2/upload.json');
curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $pvars);

$json = curl_exec($curl);
$json = json_decode($json,true);        
$res['small'] = substr($json['upload']['links']['small_square'],19)  . "<br />";
$res['original'] = substr($json['upload']['links']['original'],19) . "<br />";
$res['delete'] =  $json['upload']['image']['deletehash'] . "<br />";        
curl_close ($curl);
return $res;
}
?>

It works fine with me. 它对我来说很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM