【发布时间】:2023-04-01 03:27:01
【问题描述】:
我正在尝试从 Instagram 用户(这是我们自己的帐户)那里获取图像。下面是我正在使用的代码,但它似乎不起作用。我确实将正确的用户 ID 和 accessToken 输入到代码中。
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);
$theinfo = json_decode($result, true);
foreach ($theinfo->data as $post){
echo $post->images->standard_resolution->url;}
任何建议将不胜感激。
【问题讨论】:
-
建议检查您从 curl 请求中得到的错误
-
定义“似乎不起作用”。发生什么了?你有错误吗? php.net/curl_error 输出什么?
-
完成没有任何错误...
-
对不起柯克,没有错误,问题是图片网址没有出现。我觉得这可能与 json_decode 有关,因为如果我回显 $result 我会得到原始数据读数。
标签: php wordpress instagram-api