首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IMGUR权限被拒绝

IMGUR权限被拒绝
EN

Stack Overflow用户
提问于 2013-05-11 08:24:12
回答 1查看 1.4K关注 0票数 1

我使用的是IMGUR,我得到了以下错误

警告: file_get_contents(https://api.imgur.com/3/album/f0J59/images):打开流失败: HTTP请求失败!在第12行的C:\wamp\www\reddit_cards\imgur_test.php中,HTTP/1.1 403拒绝的权限

代码语言:javascript
复制
$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;
EN

回答 1

Stack Overflow用户

发布于 2013-05-11 09:30:50

看看我几周前创建的这个脚本,它是为了把图片上传到Imgur。

Imgur.php

代码语言:javascript
复制
  <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;
}
?>

我觉得挺好的。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16495223

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档