【问题标题】:Real-time Photo Updates - User Subscriptions实时照片更新 - 用户订阅
【发布时间】: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

【问题讨论】:

    标签: php instagram


    【解决方案1】:

    Instagram 仅为所有授予您客户端 API 权限的用户提供实时更新。当您订阅该端点时,您将开始接收已授权帐户的更新。其他用户授权后,您也将收到这些回调,而无需再次订阅。

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

    【讨论】:

    • 所以你所说的证实了我正在阅读的内容。我只向用户订阅一次...然后任何通过 oAuth 流程的用户都会被自动添加。一些用户已经完成了身份验证过程,但他们的实时帖子没有被推送。
    • 您只需订阅一次 object->user with aspect->media,然后您将获得所有经过身份验证的用户帖子。但是,我遇到了类似的问题,有很多已通过身份验证的用户跳过的帖子。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-15
    • 2011-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-21
    相关资源
    最近更新 更多