Instagram realtime get post from callback

前端 未结 3 2011
别跟我提以往
别跟我提以往 2021-02-14 11:19

Right, this is really working on my nerves, but Instagram has to do something about their bloody documentation.

I am already trying for a week to live update my website

相关标签:
3条回答
  • 2021-02-14 11:24

    When you get a subscription push, you need to query that endpoint (tag / recent).

    I normally start an synchronous thread to perform this so I can answer in under 2 seconds to Instagram.

    Then you parse that endpoint and look for a "next url" value.

    Keep querying that end point, parsing the media and going to the next url until you find your stop condition.

    For me I try to match 10 consecutive records in my DB. Basically from the tag, I store media when then meet my business rules.

    0 讨论(0)
  • 2021-02-14 11:39

    The Instagram documentation is accurate and actually well written.

    The realtime API is working correctly. As stated in the documentation:

    The changed data is not included in the payload, so it is up to you how you'd like to fetch the new data. For example, you may decide only to fetch new data for specific users, or after a certain number of photos have been posted.

    http://instagram.com/developer/realtime/

    You only receive a notification that an update has happened to your subscribed object. It is up to you to call the API to find out what that data is.

    You can call the /tags/[tag-name]/media/recent with an access token that you have previously stored on your own server or DB. Then, you should be able to compare the data returned from that endpoint with any data you have retrieved prior, and just pull the objects that you do not yet have.

    0 讨论(0)
  • 2021-02-14 11:50

    Ok strike my old answer, I changed the way I do this. Here's how I'll do it now.

    I still wait for 10 hits on my Real-time subscription, when I reach 10 I send off a new thread (if one is not already running).

    The sync thread queries my DB for a value, I need the last min_tag_id I used. Then I query:

    https://api.instagram.com/v1/tags/*/media/recent?access_token=*&min_tag_id=*

    Try it out here: https://api.instagram.com/v1/tags/montreal/media/recent?access_token=*

    You'll get 20 results, and a min_tag_id value. Append that to your url, you'll see you get no results. Wait a couple of seconds and refresh. Eventually you'll get some media, and a new min_tag_id.

    (You can ignore the "next_url" value they give you, you won't be using that).

    Basically you only need to store that min_tag_id and query until you have no more results, that means you're done then.

    0 讨论(0)
提交回复
热议问题