更新时间:2023-02-24 15:51:53
Woop找到了问题并解决了.调试起来并不容易,因为所有这些都是在Instagram到达您的页面时发生的,因此您实际上看不到输出.
Woop found the problem and solved it. It's not easy to debug because all of this happens when Instagram hit your page so you don't really see the output.
我需要做的是创建一个foreach循环来运行已解码的JSON.经过大量的调试和初步摸索之后,JSON并不是空的,它只是从JSON数组开始.
What I needed to do was create a foreach loop to run through the decoded JSON. After a lot of debugging and head scratching the JSON isn't empty, it just starts with a JSON array.
无论如何,这是现在可以生效的代码 :
Anyway here's the code now that works:
// Catches realtime updates from Instagram
if ($_SERVER['REQUEST_METHOD']==='POST') {
// Retrieves the POST data from Instagram
$update = file_get_contents('php://input');
$data = json_decode($update);
foreach($data as $k => $v) // can be multiple updates per call
{
$sub_id = $v->subscription_id; //Contains the JSON values
$user = $v->object_id;
}
}
例如,如果您想查看$ sub_id的输出,例如,建议您记录它们或通过电子邮件将其发送给自己.
If you want to see the outputs from $sub_id for example I suggest logging them or email them to yourself for example.