【发布时间】:2015-11-18 08:36:45
【问题描述】:
我在 Instagram 上为部分用户订阅时遇到了一些问题。订阅挑战正常工作,大多数用户都订阅了。他们的更新完全符合预期。
documentation 有 'myVerifyToken' 我假设这是正在订阅的用户的令牌,还是我创建的随机唯一字符串发送?
这是我订阅后得到的结果:
{"meta":{"code":200},"data":{"object":"user","object_id":null,"aspect":"media","callback_url":"http:\/\/urlmremoved\/instagram","type":"subscription","id":"000000000"}}
这告诉我用户订阅已成功,但是,在有 6 个人加入我的应用并成功完成 oAuth 流程后,我收到的唯一 POST 来自第一个要进行身份验证的成员...
订阅代码(适用于大多数用户):
$checkin_url = "https://api.instagram.com/v1/subscriptions/";
//$instagram[] for client_id, client_secret, redirect_uri
$parameters = array(
'client_id' => '{key}',
'client_secret' => '{secret}',
'object' => 'user',
'aspect' => 'media',
'verify_token'=>$access_token,
'callback_url' => '{callback url}'
);
$curl = curl_init($checkin_url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $parameters);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($curl);
curl_close($curl);
$data = json_decode($response,false);
传入的 POST 脚本(运行良好):
// 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
// load temp items into the database.
$sub_id = $v->subscription_id; //Contains the JSON values
$user = $v->object_id;
$time = $v->time;
$changed = $v->changed_aspect;
$sql = "INSERT INTO temp (tempId,tempCode,tempData1,tempData2,tempData3,tempData4,tempLong,tempTime)
VALUES (NULL, 'IG', '".$changed."', '".$_SERVER['REMOTE_ADDR']."', '".$sub_id."', '".$time."', '".$update."', CURRENT_TIMESTAMP)";
$account->mysql_Query($sql);
} // END foreach.
} // END if
【问题讨论】: