douzhi1919 2013-05-11 08:24
浏览 101

IMGUR API - 权限被拒绝

I am using the IMGUR API and I get the following error

Warning: file_get_contents(https://api.imgur.com/3/album/f0J59/images): failed to open stream: HTTP request failed! HTTP/1.1 403 Permission Denied in C:\wamp\wwweddit_cards\imgur_test.php on line 12

$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;
  • 写回答

1条回答 默认 最新

  • doushishi6513 2013-05-11 09:30
    关注

    Check out this script I created few weeks back for uploading image to Imgur.

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line