I am currently doing an integration to the Instagram API and would like my app to receive webhook notifications whenever there is new media on any Instagram account which has authorized my app via OAuth.
I've been able to write the code which sets up my app to receive notifications using the instructions here. However, I noticed that the Instagram API docs contain no information on what the data in a change notification will look like. My searches online have also come back void. I need sample Instagram webhook notification data so I can write code to parse the data and apply it for my purposes.
I would have gone ahead to expose my localhost to the internet via ngrok, so Instagram would send data to my callback URL when I post a photo to my Instagram account. However, I discovered that the Instagram API does not allow you use an ngrok URL as a callback URL.
Now the only option I have is to deploy my partially completed code to an actual web server. Hoping someone else who has previously integrated to the API can share the format of the webhook notification data. I really don't want to have to do deploy my application at this point.
I eventually had to deploy my partially completed code to a web server. I put a logger behind my webhook callback URL to record the notification data sent to it by Instagram. Below is what it looks like:
[
{
"object": "user",
"object_id": "123456789",
"changed_aspect": "media",
"time": 1506338651,
"data": {
"media_id": "1611605324545559190_123456789"
},
"subscription_id": 0
}
]
The Instagram webhook notification payload/data is a JSON array of objects, each of which contains information on a single change to an Instagram account. Each JSON object contains the following fields:
object: A string whose value is always "user"
object_id: The ID of the Instagram account on which the subject change occurred
changed_aspect: A string whose value is always "media"
time: The Unix epoch indicating when the subject change occurred
subscription_id: The ID of the Instagram subscription object through which this notification was sent. A subscription object is created to ask Instagram to send webhook notifications to your app and is essentially a callback URL.
data: A JSON object containing the following fields:
media_id: The ID of the new Instagram media object (photo, video or carousel) whose creation triggered this webhook notification
Related
I am trying to query stripe for the cancellation reason of a subscription to feed this information into our CRM system.
The information I am looking for can be found in the dashboard here:
Stripe dashboard image
I found out that the browser sends a request to https://dashboard.stripe.com/v1/subscriptions/sub_xxx but with an API key that seems to belong to user request: uk_xxx. When I send a GET request to that endpoint with my API key sk_live_xxx I dont get the same data, i.e. the following information is missing:
{
"customer_portal_data": {
"cancellation_reason": "too_expensive",
"cancellation_reason_text": null
}
}
My question now: is there a way to query this information via the standard API from stripe?
This feature is only available in the Dashboard and Sigma right now and is not available via the API.
I have setup a fully operational chat bot in Hangouts Chat orchestrated by a tailored webserver. I would like now to be able to have this webserver to interact with other Hangouts bots that I created and to route some requests to some of my other servers that will have to know which bots initiated the event.
With other provider, such as Slack, the app_id is provided in the event request data.
But with hangouts, this is not the case. I could not find any data in the request body or headers that represent either project_id or client_id.
In a more simple way my question is : "How to identify the Hangouts bot that send me an event request?" :)
An event request's response will contain an Event instance in its body, which one of its fields will be an User object. That User object will contain a name field that will represent the user's id (whether it's a human or a bot).
It will look like this:
{
"name": "users/<id>",
"displayName": "<name that appears in the chat>",
"type": "BOT"
}
One month later, I finally found the time to answer my question :)
In order to identify the Hangouts project that is calling your server, when you receive an event from Hangouts Chat, you'll find in the incoming request the header Authorization whose value is something like Bearer abcd1234.
If you decode this JWToken (ie, abcd1234 in our example), in the resulting data, you'll have a field aud which is exactly the "project number" of your Hangouts app. This "project number" can be found at "https://console.cloud.google.com/home/dashboard?project=referenceofyourprojecthere".
I'm using the /media/shortcode/shortcode endpoint of instagram to get information about a certain media with a shortcode.
https://www.instagram.com/developer/endpoints/media/#get_media_by_shortcode
The problem is when I pass a photo's shortcode to the endpoint everything works fine and I get the result I'm expecting from Instagram, however, when I pass a video's shortcode to that endpoint, the api returns the following:
{
"meta": {
"code": 400,
"error_type": "APINotFoundError",
"error_message": "invalid media id"
}
}
Which does not make a lot of sense to me since the given endpoint should work just fine with videos.
I was running into this issue too---the Instagram documentation is not super clear, but this is because of the limitations of Sandbox mode.
To help you develop and test your app, the users and media available in Sandbox mode are real Instagram data (i.e. what is normally visible in the Instagram app), but with the following conditions:
Apps in sandbox are restricted to 10 users
Data is restricted to the 10 users and the 20 most recent media from each of those users
Reduced API rate limits
From https://www.instagram.com/developer/sandbox/.
TLDR you'll need to get your app approved to have your other API calls work.
The best and the easiest way to get the media info, either being photo or video is by calling this url (GET method) Insta Fetch Media URL
Sample code written in Python.
import requests, json
def get_media_id(image_url):
url = "https://api.instagram.com/oembed/"
querystring = {"callback": "", "url": image_url}
headers = {
'cache-control': "no-cache"
}
response = requests.request("GET", url, headers=headers, params=querystring)
return json.loads(response.text)
If i use this link of the Instagram API i get nothing back:
https://api.instagram.com/v1/locations/1/media/recent?access_token=XXXX
Response:
{"pagination": {}, "meta": {"code": 200}, "data": []}
The documentation says that there are to parameters max_id and min_id, but i'm not sure how to use them.
If i use it like this:
https://api.instagram.com/v1/locations/10/media/recent?access_token=XXXX&min_id=1&max_id=20
I get the same result as above.
Both Location IDs (1 and 10) are correct.
That is cause you are in sandbox mode.
In sandbox mode you will only see your posts(and your approved sandbox users) in API, and total posts in API response is also limited to 20.
If you want to see posts in API response in sandbox mode, then you add a post tagged to a location using Instagram app, and then access that location via API, you will see just your post in API response. Once you get public_content permission and go to live mode, you will see all posts.
Here is more info about sandbox mode: https://www.instagram.com/developer/sandbox/
The behavior of the API when you are in sandbox mode is the same as
when your app is live, but comes with the following restrictions:
Data is restricted to sandbox users and the 20 most recent media from each sandbox user
Reduced API rate limits
I am running an application using Instagram's RealTime API and when I subscribe to a tag initially all is working fine, I can see for sure my response times are all within 100ms back to instagram but after about an hour, hour and a half they randomly delete my tag subscription. I check and I am not rate limited so I setup something to check my subscriptions every 10 minutes and if the tag I was subscribed to isn't returned from instagram to re-subscribe it. When running that I get back a response that it is subscribed -
{ object: 'tag',
object_id: '...',
aspect: 'media',
callback_url: 'http://...',
type: 'subscription',
id: '4479168' }
but then when I check my subscriptions again using the API Console it shows there are no subscriptions.
Does anyone have any idea why Instagram is deleting my subscription automatically.
Did you validate/confirm the subscription? You didn't mention doing it in your question so that leads me to think that maybe it's timing out after not being confirmed?
According to the API docs a POST to make any subscription will trigger a GET to your callback_url that will include:
hub.mode - This will be set to "subscribe"
hub.challenge - This will be set to a random string that your callback URL will need to echo back in order to verify you'd like to subscribe.
hub.verify_token - This will be set to whatever verify_token passed in with the subscription request.
The example URL given is:
http://your-callback.com/url/?hub.mode=subscribe&hub.challenge=15f7d1a91c1f40f8a748fd134752feb3&hub.verify_token=myVerifyToken
After parsing that callback you have to send a response including the hub.challenge value and you should have a lasting subscription.
As far as I can tell, this happens when Instagram decides you are not responding fast enough. I noticed 8 separate IPs posting the exact same subscription info (identical HTTP requests) and my app apparently has some transient lag issues. It appears that if responses are not sent immediately (100s of ms) then Instagram silently deletes the subscription and there's no way to find out.
Solution was to dump the subscription model and just poll them instead.