1

I'm trying to use the instagram api on a wordpress page. Given the following function to get the data, would anyone please point me why is my var_dump($results) return boolean false???

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/{{userId}}/media/recent/?access_token={{accessToken}}&count=20");

var_dump($result);

note: {{userId}} & {{accessToken}} are placeholders. On my code Im using the real id and token instead.

4

1 回答 1

4

正常情况下,Instagram 服务器会返回

{"pagination":{....},"meta":{"code":200},"data":[.......]}

我认为有一个 SSL 错误,尝试在 CURLOPT_TIMEOUT 下面添加这一行

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

关于 SSL 错误

cURL PHP RESTful 服务总是返回 FALSE

您可以尝试 curl_error() 和 curl_errno() 来调试 cURL 函数

curl_exec() 总是返回 false

于 2015-02-03T04:48:28.180 回答