使用cURL PHP获取instagram公共JSON feed [英] Get instagram public JSON feed with cURL PHP

查看:65
本文介绍了使用cURL PHP获取instagram公共JSON feed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用cURL从公开的instagram个人资料获取JSON响应.我坚持要回答,因为如果我尝试 var_dump 数据,它将不会产生任何结果,即一个空白字符串.我的代码有问题吗?

I want to use cURL to get the JSON response from a public available instagram profile. I'm stuck to the response, because If I try to var_dump the data it will result in nothing, a blank string. Is there something wrong in my code?

$url = 'https://instagram.com/'.$instance['username'].'/?__a=1';
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Accept: application/json') );
$data = curl_exec($ch);
curl_close($ch);
var_dump( $url );

$ instance 变量是使用wordpress小部件输入表单设置的,并且是正确的.我的问题仅在于卷曲的行为.

The $instance variable is set using a wordpress widget input form and is correct. My problems are only with the curl beahviour.

感谢您的帮助

推荐答案

脚本需要设置 CURLOPT_FOLLOWLOCATION 参数.

$url = 'https://instagram.com/'. $instance['username'] .'/?__a=1';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json') );
$data = curl_exec($ch);
curl_close($ch);

var_dump($data); // Show the response

这篇关于使用cURL PHP获取instagram公共JSON feed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆