How to Get a Users Posts with the Instagram Graph API
Вставка
- Опубліковано 11 лип 2024
- In this video we learn how get a users Instagram posts with the Instagram Graph API.
--
Live Demo ⇝ justinstolpe.com/blog_code/in...
--
Code on GitHub ⇝ github.com/jstolpe/blog_code/...
--
Instagram Graph API Documentation ⇝ / business-discovery
--
Discord ⇝ / discord
TikTok ⇝ / justinstolpe
GitHub ⇝ github.com/jstolpe/
Instagram ⇝ / justinstolpe
Twitter ⇝ / justin_stolpe
LinkedIn ⇝ / justin-stolpe-3bb05426
Reddit ⇝ / jstolpe
Twitch ⇝ / jstolpe
Facebook ⇝ / stolpejustin
Website ⇝ justinstolpe.com
SoundCloud ⇝ / justin-stolpe
--
Chapters
0:00 Intro
0:09 Tutorial Goal and End Result
0:57 Instagram Graph API Documentation Overview
2:23 Using the Facebook Graph Explorer Tool
3:23 Code/Repository/Defines Setup
3:53 Getting Datat from the API
6:06 HTML/CSS up the Data!
7:39 Outro
--
#programming #developer #coding
Omg this is IT, I have loong searched for a video on this..thank you, thank you
First time on your channel, really good tutorial, subscribed!
Hey justin,
Really appreciate it bro.
I was looking it for months, even i read all documentation from Graph API but you got it.
Thank you man.
Yeah graph api can be confusing and or a pain to figure out!
this is dynamic ? i mean when yoy get more followers change it??
I don't understand, I copied the code, but no matter what I do, it never loads any posts of profile data. How do I make it work?
thank you for making this video !!
hey buddy thanks for the video but i am actually making a web app that detects fake social media acoounts so i am currently working on my ml model but for that i need good dataset so that i am able to train my ml model/ so how can i get all these information in csv file please tell me it would be very helpful for me. thanks
Hi Justin, great video! Is there a way to count the number of views for all of the reels within an account?
Not directly but you could loop over all and tally up views.
How do I get Instagram public user's posts without their login? What type of develop app required and what APIs need to use? please guide me?
Hey great video,
Can you share the video link to get ig-user-id
Dose it work on private accounts?
Hi there! Do you know if you can use the Instagram Graph API to build an app for consumers? I understand that the documentation says the this API is intended for businesses and creators. I’m not interested in consumer media- I’m interested in various business account media so I know this is the right API to leverage. Just wondering if instagram would disallow that use case.
Yeah you can access them as long as they are business account.
hi justin, thanks for this great video, everything works just you outlined, is it possible to fetch view count with this endpoint, i could not figure aout it. I could not make the IG Media endpoint work, I get the unsupported get request error, am I missing sth with permissions and app review, also sould I use webhooks for reels and stories. thanks again
I don't think it is possible with this endpoint. You need to use the media or insights endpoint with an actual access token for the specific user which means they would need to authenticate with your application so you can get a token for them.
We'd really like to see how you requested the access and what permissions you needed to consume the APIs and Whether it is possible to get the access token silently without causing the user to go through the auth flow again.
You can use the graph api explorer tool to select permissions and generate an access token for your app developers.facebook.com/tools/explorer/
@@ytfeelslikenorthkorea I don't think this is possible through the api
@@justinstolpe Hey great video! Does the Facebook App need to be published in order to request these data through the explorer? I don't seem to find any of the permission you have such as instagram_basic, etc
@@tapizquent Make sure you have the product added in your app. You should be able to make calls to the api in the graph explorer even when you are in development mode.
tried this method but im getting this error (#100) Tried accessing nonexisting field (business_discovery) on node type (User)
How can i get, About Your Video(To find user ig)
Hello Justin!! Great video :) :D Is it possible to get location, tags, and username of posts under a hashtag in insta using graph api too? i shied away from the api since it sounded like they restricted a lot since 2020... Thanks btw!! i learned a lot, more power to the channel
does not look like it here is the documentation for insights on a media id developers.facebook.com/docs/instagram-api/reference/ig-media/insights
@@justinstolpe ohhhh, ok thanks Justin! :D :D
Hey,
That’s amazingly useful and love how ‘simply’ you demonstrated. I note this is for business accounts. Can you get ‘user_posts’ for Meta on personal accounts with the account owners permission. I know there is an API but it seems the access is only for ‘book of time line’ / parental / marketing analytics. Do you know if you can or how to?
Thanks! The api cannot be used on personal account, only business and creator accounts.
@@justinstolpe thanks for responding. Do you know any other services which can provide the same output?
@@anthonylacey9830 I don't know any
@justinstolpe How can I get the video in Arabic?
trying to follow this guide, thanks for it btw!
but would it be possible to do an array slice on to possibly limit the amount of posts like so?
$output = array_slice($userInfo['business_discovery']['media']['data'], 0, 5);
thanks! and yeah that should work
Hi there, great tutorial! How can we download instagram dp of private insta accounts? Can you please guide me?
Maybe this is a stupid question, but if I understand correctly both myself and the instagram I want to see the content of has to be a creator/business account?
So how can I tell if the account I want to show the content of is a business account?
Looks like you can check for error code of 10 possibly here is what I found on stack overflow stackoverflow.com/questions/57306647/is-there-a-way-to-tell-if-its-an-instagram-creator-or-business-account
Hello, is there a way using the instagram graph api to query the top most liked posts, say top 10 posts, for a given user id? Thank you for the content!
yes definitely, just get postids first. Now get the likes counts of these postids and make a top 10 priority queue or sort in descending order and take the first 10 postids.
Hi, do you mind showing us how did you pasted that userid(the very first entry) before putting that business query
Here is the video in my instagram graph api playlist for the user id ua-cam.com/video/Ry9UG_SfUS0/v-deo.html
is there a way to post stories automatically when there a new row added in google sheets?
no there is no way to post a story with the API
how are you Justin Stolpe? i speak from Brazil, first congratulations for the videos, it has helped me a lot in my developments related to the integration with graph instagram api, second, i would like your help to check if it is possible, from the caption of the media, i can get the accounts mentioned in the post, i saw that they appear in the json, in the "caption" field without the "@" in front, i would like to know how i can identify in the caption that a certain word is an instagram user mentioned, but without the "@". Thank you very much.
I think there is an option to request mentions with the data you get back.
do you know how I can do this?@@justinstolpe
So does this download the posts to display them or just display the media hosted by IG?
it displays the data directly from the API response
Does this return every single post for a business account? For example, if an account has 5000 posts, will it return requested info for all 5000? Or is there some sort of limit? Thanks!
No I think the default return in 25 but it does return a paging cursor which I believe can be used to get multiple pages but it requires another api call.
What if i want to download post where user input the URL of the post? Any sort of help will be appriciated.
Just going on a url you would probably need some sort of scraper to get the data out of the html. There is no api function that returns data if you pass in a url to a post.
Could you save other peoples instagrams post? Can Instagram deny your access token for using other peoples posts?
Once you get the data from the api you can decide what you want to do with it. I would think they would only deny an access token if you are spamming or using it against TOS.
Hey Justin, Getting error when using username with "_" in them while creating post, Usernames without any supported special character works fine. How to get it done for usernames with special character?
Not sure what error you are getting but I am able to get business discovery on usernames with an underscore
@@justinstolpe Yes, Please check
The “Meta” documentation is a rabbit hole and I haven’t been able to figure this out: can I pull media from any (public) instagram user? Or do I require certain permissions from them? Does that Instagram user need to have a Facebook Business page set up? Because I was looking at the “App Review Process” and one of the points mentioned that there should be Facebook SocialAuth visibly present in our application!
you can pull with business_discovery any user that is a business account
@@justinstolpe Can I do it with access token of my account or only with their? For example, I use endpoint, not my instagram ID and my access token to get data about this instagram account
iam getting this error while submitting the api "message": "(#100) Tried accessing nonexisting field (business_discovery) on node type (User)",
The IG account needs to be set as a business account and not personal to access business_discovery
@@justinstolpe I'm facing this error even in a business account
I got the same issue..why is that?
Hey! Thanks for this video! Do you know how to get instagram media id using shortcode or permalink of story or post published on instagram?
I don't think there is an endpoint for getting id from link
All i want is, when the users enter the username, fetch from the Instagram API and display the profile picture. I think i can do this using basic display API. Should the users account to be business account? And any suggestion to do this? Thanks in advance.
I don't think you can get the profile picutre url with the basic display api. But, for the graph api you can use the business discovery endpoint to query the api for a username.
Hey Justin! Do you know anything what about unavailable Test Users Facebook? Many people cant start own Apps
No not sure about that
Can we use this item to get data from any public page?
the account need to be a business/creator ig account
Hi Justine, Thank you for the detail tutorial, is there way to find follower count of normal profile ?
if not a business account you can use the basic display api I believe
@@justinstolpe Bad News Basic Display API not showing follower count, anyway thank for the tutorial and script
@@santoshraut1508 looks like the basic display api does not return that
@@justinstolpe Do you have any idea how to create a non-expiring key? I didn't find a way and facebook giving me key with expiry
@@santoshraut1508 the longest you can get is a long lived access token but as long as users keep using it the expiry date will be reset to 60 days from when they use it.
can i extract this information from any instagram profile or just the ones i manage?
the accounts have to be business or creator and then you can use business discovery to get data
Hi informative video,.. Can I grab the comments from the users post and post comments and replies to the post from our app?
thanks! you can if you just need the user access token here is the wiki wher you can see comments nd replies github.com/jstolpe/instagram-graph-api-php-sdk/wiki
Hi Justin,
Can instagram basic api be used on business account? the requirement is just to fetch posts(read only) from a buisness account.
yeah it can be used on business account but not personal
@@justinstolpe i just realized the instagram basic api is not on the product list of business account
hi justin, thanks for this great video, can you do a tutorial of making oEmbed Read Instagram?
Thanks I will look into it and see what I can do.
@@justinstolpe Could you explain please, why when i add to media(thumbnail_url) i got error
@@user-gv7pp2kv5i for business discovery I believe thumbnail_url is not a valid field to request. You need to hit the media endpoint for that specific post to get thumbnail_url
Can you get user posts from business/creator accounts (via the API) WITHOUT their explicit approval/authorisation?
Hi man, di you get answer of your question. I also want to do same thing. And doing research about it for last 1 week. Please reply it, if you got it
where did you got the access token from ?
check out my access tokens video ua-cam.com/video/_teASazXZ3s/v-deo.html
Hii, love your video, is there a way to get the stories from an account like this?
Yeah here is a link to the wiki github.com/jstolpe/instagram-graph-api-php-sdk/wiki/Stories
Hi, I did a request in Java but it returned me that some permissions were missing. I read the documentation and they said that I needed instagram_basic, page_read_engagement and pages_show_list permissions. Apparently I need to give information about my company if I want to add these permissions to my app. But I don't have any company and i just want to create an app for trying.
Is there any other methods to do it ?
Yeah you can get access to these things if your app is in dev mode. Just make sure you have users set for the correct roles in the facebook apps dashboard.
@@justinstolpe Thanks, do you know if there's an API for Instagram which allows to download videos from any Instagram account (even non business accounts) ?
@@Elii1se no there is not an api for that
@@Elii1se no there isn't
Hii justin,
It doesn't work for test user
Error:- cannot be loaded due to missing permissions
I want to create a screencast for app review for permissions like, Oembed_read,user_posts,user_likes but these permission are not working for test users
I have not used test users so i am not exactly sure about them. You might need to use an actual account tied to a facebook page.
@@justinstolpe
Okay, Thanks for your reply
Hey Justin,
Thanks for the video. I keep getting an error "Unsupported get request, Cannot be loaded due to missing permissions. What should I do for the same?
Thanks! That error means the access token you generated does not have the correct permissions so you probably need to create a new access token with the permissions required.
@@justinstolpe alright thank you so much for your response. But I did follow your procedure from the beginning. And I then searched on stack overflow for the same issue. It came to my knowledge that I had to review my app as per policies. Is that necessary as I am trying this on my own and don't have a business?
@@justinstolpe hey Justin. can you specify which permission that should be enabled before doing this?
@@buatmaen2225 THe permissions in the vid should work. On your own you can use dev mode but as mentioned you need the app to go through facebooks review process for you to make the app in live mode or it won't work.
ddoes this work for private profiles?Like if we want to get posts of people that we follow
If you have an access token for their account I think it is possible.
How to get api key? and if that is diff than acess token
Check out this video ua-cam.com/video/qk8RAawrkhY/v-deo.html
great tutorial, but unfortunately too much docs to read and we need a fb biz account
I dont know if you check these anymore, but im getting this error:
{
"error": {
"message": "(#12) singular published story API is deprecated for versions v2.4 and higher",
"type": "OAuthException",
"code": 12,
"fbtrace_id": "A3yGZT3HBQH0Fcn0C5LLwiy"
}
}
any reason why?
yeah that is deprecated for the new api version
@@justinstolpe do you have a more updated tutorial or can point me in the right direction
@@amirmobarak6889yeah check out my instagram graph api playlist ua-cam.com/video/WpiJeVqNJQk/v-deo.html
Is it possible to post a URL with image to Instagram through API?
if you are posting an image you just need the image on a public server then you pass the URL to the API
1:13 which video? You have many videos, i'm confused
Here is the most recent one I have for it ua-cam.com/video/Ry9UG_SfUS0/v-deo.html hope it helps!
how is this legal to be able to use and get other users photos and data and use it else where? isn't this copy right infringement?
Well the user has to authorize your app in order for you to make api calls on their behalf and get their data.
**Look at separate facebook login or App Review videos/docs
Does this also works for reels?
Have not tested but it should return in the data set
I couldn't do it. Probably because of the complex structure of the reels section.
for me it works only for solo pictures (not videos, and carousels). Do someone has an idea of what's going on ?
Check and make sure the fields you are requesting and it should return an array of children if the post is a carousel.
where is video to get ig user id?
here it is ua-cam.com/video/763kVf9fvqA/v-deo.html
Hey Justin, Can I also get 'the number of likes' and 'the number of comments' of other person's post?
yeah it should come back in the response as like_count and comment_count
Bro this php code makes head hurt
can you hack my ex girlfriend's instagram account?
hey. how to fetch other people story?
here is the video I made on stories ua-cam.com/video/EmIFd4xbWnc/v-deo.html
@@justinstolpe not my account story but target account story
@@faysalahmed2619 you just need an access token for the target account. Checkout my access tokens tutorial on how to do it.
@@justinstolpe can you make tutorial on this topic?
Still works in 2023?
Yeah it is
How to get views of video of user
calling insights endpoint on the post can get you more details or I believe if it is a video you might be able to request video_views field.
Hey I have used Instagram graph API buisness discovery endpoint but when I hit the url there was an error -
"message": "(#10) Application does not have permission for this action"
what permission i want to add.
I have allow these permission -
pages_show_list, instagram_basic, pages_read_engagement, public_profile
Please help me
Hey Justin, please help me
@@amanjitmodak6905 Looks like the documentation says
instagram_basic
instagram_manage_insights
pages_read_engagement or pages_show_list
developers.facebook.com/docs/instagram-api/reference/ig-user/business_discovery
Have you solved this problem? This happened with me too, and any permission is making it work. If you already solved this, please, share with me! Thanks.
@@fx6373 Also make sure your account is the owner or admin of the facebook page
@@justinstolpe These three/four permissions saved my day! I had been struggling get any access with the same error "(#10) Application does not have permission for this action" for days. Thanks for the tip!
I am getting Tried accessing nonexisting field (business_discovery) on node type (User) error. My IG account is business account, and I have enabled all the permissions. Also enabled the Graph and Basic API. Your help will be greatly appreciated. I am trying for last couple days. Thanks
Not exactly sure but you might need to double check your permissions on the access token you are using.
@@justinstolpe getting same error, I have enabled all permissions & account is business as well. I think there is some major change in api's. It will be very helpful if you can check and update us.
@@redecormyhome4335 I would test out your tokens and user ids in the facebook graph explorer so you can debug it. TI am not aware of any major breaking changes as the demo link for my code is still working.
@@justinstolpe Finally I got it working. But there is only 1 issue. For some accounts, all fields EXCEPT like count show up. I tested with 8 different creator and business accounts. For 6 of them, all data including like count shows up. For 2 other accounts, all data except like count shows up. What's going on? Could you help.
By the way, thanks a lot for such a helpful tutorial I just hit the like button. Cheers
@@mridul7200 How its working? I got same error too, and still stuck until now
How to get comments on each media returned using business_discovery?
Hey Justin, can you do a tutorial of making Instagram Direct Message by using the Instagram Graph API?
Thanks for the all Instagram Graph API Tutorial
You are awesome
Thanks! I will check it out and see if the API can do it.
@@justinstolpe Thanks a lot Justin
only get "type": "OAuthException",
"code": 100,
What
$pageId = 'YOUR-PAGE-ID'?
$accessToken = 'YOUR-ACCESS-TOKEN-HERE' from IG or FB?
Facebook Page ID and access token also but make sure you have the right permissions. Check out my access tokens video for more info.