我一直在为一个班级项目与实时 instagram api 搏斗。我有一个订阅和回调脚本,可以将数据推送到 mongoDB。一切都很好,我收到了更新,但是 $data 数组在所有这些上都是空的。我似乎无法找到为什么我没有收到更新后的数据。任何帮助,将不胜感激。这是我的代码,我附上了我的 mongoDB 结果的屏幕截图。
***订阅脚本
<?php
//Subscribe
//ALL YOUR IMPORTANT API INFO
$client_id = 'xxxxxxxxxxxxxxxxxxxx';
$client_secret = 'xxxxxxxxxxxxxxxxxxxxxx';
$object = 'geography';
$lat = '39.73';
$lng = '-104.98';
$radius = '5000';
$aspect = 'media';
$verify_token='';
$callback_url = 'http://www.callback.com';
//SETTING UP THE CURL SETTINGS
$attachment = array(
'client_id' => $client_id,
'client_secret' => $client_secret,
'object' => $object,
'lat' => $lat,
'lng' => $lng,
'radius' => $radius,
'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 YOULL SEE A 200
print_r($result);
?>
* *回调脚本
<?php
//Callback
if (isset ($_GET['hub_challenge'])){
echo $_GET['hub_challenge'];
}
else {
//database config
$dbhost = '@myserver';
$dbname = 'test';
//connect to database
$m = new Mongo("mongodb://$dbhost");
$db = $m->$dbname;
//select the collection
$collection = $db->instagram;
//This is an update
$myString = file_get_contents('php://input');
$ALL = date("F j, Y, g:i a")." ".$myString."\r\n";
file_put_contents('activity1.log', $ALL, FILE_APPEND);
$answer = json_decode($myString);
$collection->save($answer);
}
?>
当我打开 RoboMongo 时,我收到的键是对象 ID、更改的方面、对象、时间、订阅 ID。然后有一个始终为空的数据数组。我不知道如何从中获取信息。