Instagram API for ADS posts not working - api

I get instagram post details (likes, comments) by using the media endpoint:
$data1 = file_get_contents("https://api.instagram.com/v1/media/$media_id/likes?access_token=$access_token");
This works for normal posts from my feed, but when I input the $media_id for an instagram post that is an AD I always get invalid media id
{
"meta": {
"error_type": "APINotFoundError",
"code": 400,
"error_message": "invalid media id"
}
}
Are ads treated as different types of posts or the API is unable to retrieve any details from them?

Yes, the ads are treated like a different type of post and can only be managed or fully read by means of the Facebook APIs. Try the Graph API, the Marketing API or the Business Manager API, that's where I got the most useful tips and results.
(sorry, dont have enough rep to post more than two links. But don't worry, you'll find it on google in a heartbeat)

Instagram ADS API has been integrated into Facebook Marketing API.
All the details are here: https://developers.facebook.com/docs/marketing-api/guides/instagramads/ads_management/v2.6
There is a workaround to get some details on an AD. If you query the oembed endpoint, like this: https://api.instagram.com/oembed/?url=https://www.instagram.com/p/BAZV-jVlFGp/ you get some data.
I wasn't able to get any comments though.

Related

How to get the Twitter followers count using Twitter API (in 2022)?

I am surprised to see that there is no way to simply get the number of followers for one Twitter account.
I found many answers (Follower count number in Twitter, How to obtain follower count in Twitter API 1.1?, How to get followers count from twitter, Twitter follower count number) which are way too old as they either use services that do not exist anymore, or make use of the Twitter API v1.1 (instead of the current v2 API).
I found an interesting way (but unsupported) to get the number of followers, using the code of their follow button.
https://cdn.syndication.twimg.com/widgets/followbutton/info.json?screen_names=elonmusk
However, I am looking for an official way to retrieve this what I think a simple data from Twitter.
Also note that the official Twitter v2 API does not allow to fetch a count but only to list the followers page per page, which is far from what I try to achieve.
https://api.twitter.com/2/users/44196397/followers
Yes, there is a simple way to do this using the Twitter API v2!
The follower and following counts for a user are part of the public_metrics fields in the User object.
The API endpoint and parameters are in the format
https://api.twitter.com/2/users/[ID]?user.fields=public_metrics,[any other fields]
Here's an example of the output, using the twurl command line tool (which handles the authentication etc, you may need to use a library to help with OAuth):
$ twurl -j "/2/users/786491?user.fields=public_metrics,created_at"
{
"data": {
"id": "786491",
"username": "andypiper",
"created_at": "2007-02-21T15:14:48.000Z",
"name": "andypiper.xyz",
"public_metrics": {
"followers_count": 16570,
"following_count": 3247,
"tweet_count": 134651,
"listed_count": 826
}
}
}
In case you want to get followers count not by user id but using user name
https://api.twitter.com/2/users/by/username/{username}?user.fields=public_metrics
Also you will need to create app in Twitter Developer Portal, receive auth token and use it in your request's authorization header
Authorization: Bearer {token}

Foursquare photo added via api not showing in venue detail

Need foursquare API experts help, I have a response of API endpoint "add photo" and it contains photo id which can be view able on API explorer but on web venue page no photo is showed not even in venue detail API call or venue/venue_id/photos
https://foursquare.com/developers/explore#req=photos%2F5d5c2af567339e0008d19915%3F
this is the photo uploaded, in the response there is a venue id which is not showing this photo in detail and web venue page.
Without knowing your parameters, API calls, or response data (I assume it's JSON), this is the best I can do as far as answering your question:
If you have the photos' ids, then you could try this endpoint:
GET https://api.foursquare.com/v2/photos/PHOTO_ID
That endpoint has a venue field in the response; check to see if it's pointing to the correct venueId.

Instagram API - Getting invalid media id with video shortcode

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)

Instagram API doesn't response correct?

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

Is it possible to get instagram media for a location with a foursquare id in a single call?

I have a bunch of foursquare ids and I want to be able to pull instagram media with those foursquare ids.
Currently I only see one way to do this and it requires two API calls. You must first do a call to the search API using foursquare_v2_id (example call). That will return the instagram ID. Then I must do a second call to the media API using the instagram id to retrieve media (example call).
Does anyone know how to achieve these results (getting media for a location based on just a foursquare_id) with only one api call?
You can get this information through the foursquare API, with the venues/photos endpoint. See the documentation here.
This will return a list of photos for the venue, including their source. You can use this to either return all images for a venue, or just those from instagram.
After contacting Instagram it is clear that there is no way to do this at this time. If that ever changes I will come back and re-answer this question with the proper solution.
I think you have to user below api to get instagram images:
https://api.foursquare.com/v2/venues/423a1a00f964a5202f201fe3/photos?oauth_token=Z5RRDGQUWEAFCANX2OT0R2O5QUWYOP1EMOCNXT1PQWKMHVNG&v=20130706&limit=200
Using foursquare id and foursquare oaurh token you can get perticular venue images.
In response, you can check "source":{"name":"Instagram","url":"http://instagram.com"}.
source name is Instagram means it is a instagram image.
Refer: https://developer.foursquare.com/docs/venues/photos