简体   繁体   English

实时照片更新-用户订阅

[英]Real-time Photo Updates - User Subscriptions

I'm having a few issues with subscriptions for some users on Instagram. 我在Instagram上为某些用户订阅时遇到一些问题。 The subscribe challenge works correctly and most users get subscribed. 订阅挑战可以正常工作,并且大多数用户都可以订阅。 Their updates work completely as expected. 他们的更新完全按预期工作。

The documentation has 'myVerifyToken' I'm assuming that's the token of the user that's being subscribed or is this a random unique string I create to send? 文档具有“ myVerifyToken”,我假设这是正在订阅的用户的令牌,或者这是我创建要发送的随机唯一字符串吗?

Here is the result I get once I've subscribed: 订阅后得到的结果如下:

{"meta":{"code":200},"data":{"object":"user","object_id":null,"aspect":"media","callback_url":"http:\/\/urlmremoved\/instagram","type":"subscription","id":"000000000"}}

This is telling me that a user subscription has been successful however, after having 6 people join my app and go through the oAuth process successfully the only POST's I receive are from the first member to be authenticated... 这告诉我用户订阅已成功,但是在有6个人加入我的应用程序并成功完成oAuth流程后,我收到的唯一POST是来自第一个要验证的成员...

Subscription Code (works good for most users): 订阅代码(对大多数用户有效):

$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);

Incoming POST script (works nicely): 传入的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

Instagram only offers real time updates for all users that give your client API permission. Instagram只为所有授予您的客户端API权限的用户提供实时更新。 When you subscribe to that endpoint, you will start receiving updates for accounts that have already authorized. 订阅该端点后,您将开始接收已授权帐户的更新。 After another user authorizes, you will receive those callbacks as well without having to subscribe again. 在另一个用户授权之后,您也将收到这些回调,而无需再次订阅。

From the Instagram documentation: 从Instagram文档中:
At the current moment we only allow you to subscribe to all users that have authenticated your application - not individual users.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM