Imgur上传错误

时间:2017-04-30 13:59:42

标签: php image laravel imgur

我正在使用Imgur从我的网站上传照片。

这是我的代码

$client_id = '*********';

$image = file_get_contents($_FILES['update_profile_photo']['tmp_name']);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.imgur.com/3/image.json');
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Client-ID $client_id"));
curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => base64_encode($image)));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$reply = curl_exec($ch);

curl_close($ch);

$reply = json_decode($reply);

echo "<h3>Image</h3>";
printf('<img height="180" src="%s" >', $reply->data->link);

echo "<h3>API Debug</h3><pre>";
var_dump($reply);

当我第一次上传文件时,它会打印出图像。但是从下一次尝试我无法查看文件,并且在laravel中我收到类似这样的错误

enter image description here

清除printf('<img height="180" src="%s" >', $reply->data->link);以检查var_dump()的结果时,它会给我这样的

object(stdClass)#219 (3) {
  ["data"]=>
  object(stdClass)#215 (3) {
    ["error"]=>
    object(stdClass)#212 (4) {
      ["code"]=>
      int(1016)
      ["message"]=>
      string(27) "Banned country attempt (IN)"
      ["type"]=>
      string(16) "Exception_Logged"
      ["exception"]=>
      array(0) {
      }
    }
    ["request"]=>
    string(13) "/3/image.json"
    ["method"]=>
    string(4) "POST"
  }
  ["success"]=>
  bool(false)
  ["status"]=>
  int(400)
}

我住在印度(在消息中告知禁止国家的尝试)
我想知道如何修复此错误?为什么第一次它有效,现在它没有。

我在localhost,还没有托管。
这是我的代码问题吗?

请告诉我如何解决此问题

1 个答案:

答案 0 :(得分:2)

Imgur在印度被屏蔽,因此您无法访问该API。

解决此问题的唯一可靠方法是通过代理访问API。

来源:http://thehackernews.com/2015/01/indian-government-blocks-32-sites.html