【问题标题】:Don't get any response by Instagram API没有得到 Instagram API 的任何响应
【发布时间】:2014-11-05 22:43:26
【问题描述】:

这是我的代码:

<?php

  function fetchData($url){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 20);
    $result = curl_exec($ch);
    curl_close($ch); 
    return $result;
  }
  $result = fetchData("https://api.instagram.com/v1/users/search?q=majoe_47&access_token=[hidden]");
  var_dump($result);
  $result = json_decode($result);
  foreach ($result->data as $post) {
    // Do something with this data.

  }
?>  

输出:bool(false)

直接网址输出:

{"meta":{"code":200},"data":[{"username":"majoe_47","bio":"Breiter als der T\u00fcrsteher","website":"http:\/\/www.facebook.com\/majoeduisburg","profile_picture":"http:\/\/photos-a.ak.instagram.com\/hphotos-ak-xfa1\/10584773_1460870534165160_603268483_a.jpg","full_name":"Majoe","id":"256143447"} [..more code ..]}]}

为什么我没有得到任何回应? :/

【问题讨论】:

  • 您应该删除您的访问令牌!只是为你做的;)

标签: php api instagram


【解决方案1】:
function fetchData($url)
    {
        $channel = curl_init();
        curl_setopt($channel, CURLOPT_URL, $url);
        curl_setopt($channel, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($channel, CURLOPT_CONNECTTIMEOUT, 10);
        curl_setopt($channel, CURLOPT_TIMEOUT, 10); 
        curl_setopt($channel, CURLOPT_ENCODING , "gzip");
        curl_setopt($channel, CURLOPT_VERBOSE, true);
        curl_setopt($channel, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($channel, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
        curl_setopt($channel, CURLOPT_SSL_VERIFYPEER, FALSE);     //add this
        curl_setopt($channel, CURLOPT_SSL_VERIFYHOST, FALSE);     // and this line to support https
        $output = curl_exec($channel);
        curl_close($channel);
        return $output;
    }

【讨论】:

  • 他发布的功能有什么问题?它应该工作得很好。
  • @AmalMurali 我不知道我做错了什么,但现在它完美运行
  • @AmalMurali cURL 将返回 bool(false) 因为 https
  • @CSGO:哦,对了。它出于某种奇怪的原因在我的系统上运行。但你是对的(+1);我没有注意到https
猜你喜欢
  • 2018-06-18
  • 2019-07-28
  • 1970-01-01
  • 2023-01-19
  • 2019-09-02
  • 1970-01-01
  • 2014-01-30
  • 2021-11-02
  • 1970-01-01
相关资源
最近更新 更多