从Instagram获取图像,总是null


Getting images from Instagram, always null

我在本地主机(WAMP服务器,启用CURL)上开发了一个小脚本,用于从Instagram检索图像。基于这个脚本:参见教程,我也在Instagram上设置了变量。我不确定是什么问题更具体或如何解决它(可能与身份验证)。

    <
  • 用户ID/gh>客户机ID
  • 客户秘密
  • <
  • 网站URL/gh><
  • 重定向URI/gh>

这是我的用户http://instagram.com/krondorl

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/280766222/media/recent/?access_token=df04c6989eaf4490bdac1f82554182bb");
$result = json_decode($result);
var_dump($result);

试试下面为我工作的代码。确保你的URL是正确的。

$json_url  ='https://api.instagram.com/v1/users/280766222/media/recent/?access_token=df04c6989eaf4490bdac1f82554182bb';
// Initializing curl
$ch = curl_init( $json_url );
// Configuring curl options
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array('Content-type: application/json') 
);
// Setting curl options
curl_setopt_array( $ch, $options );
// Getting results
$results =  curl_exec($ch); // Getting jSON result string
$json_decoded = json_decode($results);

顺便说一下,我检查你的URL碰巧是不正确的,给我下面的错误。

{"meta":{"error_type":"OAuthAccessTokenException","code":400,"error_message":"The '"access_token'" provided is invalid."}}

在您尝试代码之前,请先在浏览器上尝试URL,看看URL是否正确。