我正在努力了解如何获取查找特定标签的 Instagram 订阅的结果。最终,我想做的是在发布带有我要查找的标签的图像时,将链接添加到照片以及将用户名添加到数据库。
我能够毫无问题地创建我的订阅,但现在我不确定如何从订阅中获取 POST 信息。
使用两个文件...subscribe.php 和 callback.php
订阅.php
<?php
//ALL YOUR IMPORTANT API INFO
$client_id = 'XXX';
$client_secret = 'XXX';
$object = 'tag';
$object_id = 'taglookingfor';
$aspect = 'media';
$verify_token='';
$callback_url = '(full URL here)/callback.php';
//SETTING UP THE CURL SETTINGS...
$attachment = array(
'client_id' => $client_id,
'client_secret' => $client_secret,
'object' => $object,
'object_id' => $object_id,
'aspect' => $aspect,
'verify_token' => $verify_token,
'callback_url'=>$callback_url
);
//URL TO THE INSTAGRAM API FUNCTION
$url = "https://api.instagram.com/v1/subscriptions/";
$ch = curl_init();
//EXECUTE THE CURL...
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //to suppress the curl output
$result = curl_exec($ch);
curl_close ($ch);
//PRINT THE RESULTS OF THE SUBSCRIPTION, IF ALL GOES WELL YOU'LL SEE A 200
print_r($result);
?>
回调.php
<?php
if (isset ($_GET['hub_challenge'])){
echo $_GET['hub_challenge'];
}
//This is an update
else {
$myString = file_get_contents('php://input');
$answer = json_decode($myString);
echo $answer;
}
?>
在我的 callback.php 中,我试图回显 json_decode 的结果......但这也引出了一个问题,我将如何捕捉那个回声?抱歉,这可能真的很傻,但是我如何捕捉到回调.php 脚本被带有我正在寻找的特定标签的新图像触发的时刻。正如我提到的,我希望做的是获取 $answer 中的信息并将一些信息插入数据库。
我是新来的,所以任何帮助将不胜感激。太感谢了!!