Instagram Subscription API always creates just 1 subscription and overwrites the other

186 Views Asked by At

I finally figured out how to create subscription. And it works fine, I get pushes from Instagram everytime I add new media.

Now the problem is, I've set up a mechanism so that our users can sync their insta to our site. So I should be able to create multiple subscriptions to the same client_id. From what I understand subscriptions is built to do just that. Now when another user comes along and creates a new subscription the other one (created with another instagram account) is getting deleted and replaced. I receive a successful instagram subscription with the exact same subscription_id as the one for my other subscription. When I list the subscriptions with curl I only see 1 subscription with the subscription_id 0.

{"data": [{"id": 0, "type": "subscription", "object": "user", "object_id": null, "aspect": "media", "subscription_id": 0, "callback_url": "**callbackurlReplacedForSecurityReasons"}], "meta": {"code": 200}}

How can this be?

From the docs the call to create the subscription looks like this:

curl -F 'client_id=CLIENT-ID' \
 -F 'client_secret=CLIENT-SECRET' \
 -F 'object=user' \
 -F 'aspect=media' \
 -F 'verify_token=myVerifyToken' \
 -F 'callback_url=http://YOUR-CALLBACK/URL' \
 https://api.instagram.com/v1/subscriptions/

Now I've set the verify_token to a unique string for each call in order to test if that was the problem as the doc said it should be individual for every request but it did not matter, same problem.

The problem exists for Sandbox mode and Live mode.

Is there anything else I am missing here? Am I getting this whole feature wrong? Is there only a way to create 1 subscription per client_id but if so why does it give me back a subscription_id?

1

There are 1 best solutions below

0
On BEST ANSWER

Ok I've figured it out myself by surfing the web somewhere I've found a hint that enlighted me :D It is really poorly documented how subscriptions work on instagram side.

I was getting that feature completely wrong. My understanding was, that I have to create a subscription per user and if the user don't want it anymore he just deletes it.

How it really works is as follows:

You create 1 subscription for the whole client (not every user). Each user just has to authorize the application and THATS IT! Your callback method will now receive all updates of those users who have authorized your client. If they don't want it anymore they either have to deauthorize your client (which is very unlikely that he will find that option ;)) or you just don't react to incoming messages anymore.

A bit off topic but good to know: I also want to add the structure of the json that is coming from insta to your callback because this is not documented on instagram side (you have no idea what you get without testing it yourself)

the json you receive when new media is posted looks as follows:

[{
"object": "user",
"object_id": "4857061161",
"changed_aspect": "media",
"time": 1502958709,
"data": {
    "media_id": "1583254852313311736_4857061161"
},
"subscription_id": 0

}]

object_id is the instagram user id which you can use to differentiate between users and map to your internal user in the authorization process! Also notice that it is wrapped in an array for whatever reason...