【问题标题】:PHP JSON ERROR json_decode() file_get_contents($urlPHP JSON 错误 json_decode() file_get_contents($url
【发布时间】:2015-03-19 03:24:45
【问题描述】:

我收到这个错误

注意:试图在
中获取非对象的属性警告:无效 为 foreach() 提供的参数

$username = strtolower($username); // sanitization
$token = $token;
$url = "https://api.instagram.com/v1/users/search?q=".$username."&access_token=".$token;
echo $url;
$get = @file_get_contents($url, 0);
var_dump($get);
$json = json_decode($get);
//var_dump($json = json_decode($get));

foreach($json->data as $user)
{
    if($user->username == $username)
    {
        return $user->id;
    }
}

【问题讨论】:

  • 您已经拥有var_dump。调查
  • 在试图找出脚本不起作用的原因时抑制可能的错误/警告并不聪明……删除@

标签: php json instagram-api


【解决方案1】:

根据您的代码,您没有进行身份验证 (https://instagram.com/developer/authentication/#),因此您的 $json = false 并且您正在尝试使用 false 的属性。这就是为什么您会收到该错误

【讨论】:

    猜你喜欢
    • 2013-06-12
    • 1970-01-01
    • 1970-01-01
    • 2020-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-30
    • 2011-01-21
    相关资源
    最近更新 更多