Instagram Graph API Access Tokens
Вставка
- Опубліковано 15 січ 2020
- In this video we learn how to get an access token for use with the Instagram Graph API. The access token lasts for 60 days and can be used to have full control over social interactions on an Instagram account as along as the Instagram account is set to either a professional business/creator.
--
Code on GitHub ⇛ github.com/jstolpe/blog_code/...
--
Live Demo ⇛ justinstolpe.com/blog_code/in...
--
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
--
#programming #developer #coding
Publishing Content with the Instagram API is now possible! Here is how to do it -> ua-cam.com/video/1lKzu3UVJso/v-deo.html
Hello, Justin. Glad to know that it's now possible. Thanks.
Literally spent 2 days trying to figure this out. Thanks!
Glad it helped you out!
Thank you very much, I haven't found any video about graph api
You are welcome! Thanks for the comment!
Thanks for a very helpful video topics for coding😀
Hey thanks a lot man! I had everything setup working with FB Graph API for Facebook. This (and another video of yours) quickly helped me out to get Instagram authenticated. I was hoping it would just auto post to Insta since I have it set to do so for Facebook but I guessssss I have to implement that too :)
Subbed!
waiting for post content with instagram api hehe
Here is how to post content ua-cam.com/video/j65W-L-gQs4/v-deo.html
Hello Justin. I'm a student and new to the APIs. I am using Instagram product instead of Facebook Login and I am confused about should I still do all the steps about Facebook Login. (because it's the only thing we're making differently.) Without it, I managed to get the authorization code but I'm failing to obtain short lived access token. I'm facing an error, 'Invalid platform app'. Well, I'm not using php and I tried to make a POST request both from Postman and HTML form POST method but same error in both ways.
Thanks for the helpful video! I have a question about 8:47
When I go through the process of logging in with an Instagram business account, the UI only mentions "Instagram professional accounts". I'm fairly confident that my IG account is of type business, since I'm able to make posts onto Instagram with the graph API. The permissions I'm using are instagram_basic, pages_show_list, business_managament and instagram_content_publish
I've also looked through the docs but I've never managed to fix this issue.
Do you have any insight on how to fix this?
Thank you so much.
Thanks mate. You helped.
Glad to hear it!
Thanks for the tutorials Justin, I really appreciate. I'm trying to implement the hashtag search inside a client's web project and I'm wondering the roundabouts for not needing the continuous login on Facebook. Do you think it could be possible to refresh the long live access token, once I linked the app for the first time, using the "refresh_access_token" api ?
Thanks! Yes, refresh the long lived token so it does not expire.
so great!!!
I need to get latest insta posts attached to a hashtag.....i checked their documentation for that....but how to get redirected URI and hashtag id....i'm not getting..can you plz help?
Hi how would you do if you want to use the Instagram Graph API for a swift iOS application?
i feel a lot has changed from the API end after the Meta acquisition. I've looked at a lot of other articles/video, and there's one thing that has been confusing me and i couldn't find out about in this context was "Valid OAuth Redirect URIs". Can anybody help me understand what that is and how to get it?
hey...I'm also stuck wiht this. It's been over 5 months since you posted this comment...may you please provide me solutions if you arrived at any?
@@adarshxd6274 hi I enquired a bit into it. I realised that now , you have to be registered as a company and show proper address proof and other documents for it (which an individual doesn't have) to get the permissions. So ultimately this route can't be taken at all. If I'm wrong now or a few months later I would be grateful if someone could Correct me.
Thank you very much
just tried this out for school project, thank you so much!!!
Is it loading for you
@@PraveenKumarkimi yes, I just tried it last week it works
@@yesman4005 yeah it's working for me too.. I got error with autoloader
@@PraveenKumarkimi couldn’t it be the path? I have problem while loading autoload.php too, I simply change the naming of the path 😆
@@yesman4005 i found error because of composer getloader function, so I installed composer files & fb sdk using terminal.. & it worked
Hi Justin. i’m just building a react website and want to show someone’s posts in my page. should i do all this stuff? do i have to create a backend for this react website i’m doing?
Actually i’ve made it with my own account but the goal is doing it with others account.
I watched several videos published by you. It's well explain and understandable. Thanks for your great help.
This video is more valuable due to difficult to find a good tutorial for Instagram.
Is this the way to implement login with Instagram? How to use unlike instagram account login with Instagram ?
Thank you! There is no "login with instagram", instead you need to implement the login with facebook. Check out my channel for videos on logging in with facebook.
Hi, Thanks for useful videos. Does it work just for facebook developer accounts?I mean when I test it with a non develover facebook account, facebook login doesn't ask permissions.
Exactly what I needed. Thanks, Justin!
Glad to help!
Hey Justin, great video really helpful we're just migrating to the Graph API - I can't find anything any more about how to get permissions to post directly to Insta, do you have any insights?
Yeah right now there is no endpoint for actually posting content through the api
Thanks, Justin, how to get the access token expiry days?
Thanks Justin!, Wath if I don't hace a valid OAuth tu put? does it mean I can't get permissions?
thanks for everything
thank you!
hello! great an thanks again Justin! Is it possible to also get the expire date token's..?..
$accessToken->getExpiresAt() ...not working....
First, good job and thanks for the videos really helpfull but please can you give us a videos on how to manipulate that api with python. Thanks.
I am not python master :) but I can look into this
Great video Justin! Can we get a little more clarification on obtaining the token and the redirect URI? I'm trying to recreate this on my own computer and trying to figure out how to approach this/
Thanks! The redirect uri it where Facebook will send the user after they have authorized your application. They also add on get variables which you then use to generate the users access token. Here is the flow hope it helps!
1. User on your login page clicks "login with FB"
2. Users is taken to FB and authenticates with your app.
3. Facebook sends the user to your redirect uri with more get vars.
4. You use the get vars to generate a user access token.
@@justinstolpe Got it. I am just trying to do this for myself and get a token so I can post to Instagram from my python script. Is there a simpler way to do this? I don't have a website to use for the URI.
@@mordye13 ah, In that case it is very easy. You can generate an access token with the facebook graph api explorer tool
developers.facebook.com/tools/explorer/
@@justinstolpe Awesome! Any idea how long this access token is valid for? I plan on running my script to post once a day.
@@mordye13 once you create a token there is a debug token button you can click and then you should be able to click on extend the tokens lifetime
Hi Justin, how would I go about this differently if I just wanted to collected users' media and media data, without the whole facebook login and all that
Here is my newest video on gettting media for a user I think it will help you ua-cam.com/video/8tu4DPSIQyA/v-deo.html
Do you need a domain for this to work?
Hi Justin, Thank you very much for the tutorial. But I have a question. I'm trying to get the data like followers count, media, etc without implementing a Facebook login. Basically, what I want to do is, Once I get the username from the basic display API, I'll use that username and send a request to the graph API to get followers count and media data. I don't want users to login with Facebook. I want to handle graph API access tokens from the server-side. Is there any possible way to do this?
The graph api requires a authentication dialog from the user so they can authorize your app to get their info.
Thanks very useful, I have a question it is possible to make a Facebook login and obtain data form basic display Instagram api ?
For the basic api you would need to use the authroization dialog and get a user access token for use with the basic display api
Thx for video! And how long-live token should be refreshed after ~60 days? Again with same way(login -> get short -> get long)?
Yea but there is a refresh endpoint where you can simply exchange the current long token for a new long token if the current long token is not expired.
The refresh endpoint belongs to Instagram Basic Display APIs. I use the the graph apis because i need to post contents... But I cannot find a way to refresh long live tokens. Am I missing something?
Thanks for your good tuts. I think instagram updated api cause my code worked a few days ago and not working today. Can you check and remake this part?
Might be your access token expired, not sure what your error is though.
Sir, I want to ask, where do I get Valid Oauth Redirect URIs? Thank you
The redirect uri is simply the URL for IG to send the user back to after they authorize your application. So, it should be something like www.yoursite.com/auth. Then after the user authorizes your application, IG would redirect them to www.yoursite.com/auth?code={code} so you can use the code to genereate an access token.
@@justinstolpe what to do if I am trying to use this api in app ?? URL doesn't exist there what to do then please help..
I am having an issue, it is giving me an error for not having polyfills.php (... Facebook/polyfills.php): failed to open stream: No such file or directory...)
Might need to do a composer install/update. That file is in the vendor folder.
sir where i can find my "valid oauth redirect uris"??
the redirect uri is where IG will send the user after they authorize your app so it should be the url to your webpage where you will handle and get the access token after the user has authorized through IG
@@justinstolpe how to set this webpage up?
Thank you very much, but I couldn't get client id in manage clients on my instagram because there is a button named "Registration Disabled". What should I do Justin? It's so important for me.
I am not sure where you are seeing this buttong named "Registration Disabled"
@@justinstolpe its in manage clients
@@richardmartinenriquez7470 I think you are using a different api.
I have one question. Only my insta account should be business or every user connecting their instagram with me must also be business?
All the accounts you want to use the graph api oh need to be business.
Thank you very much ! How i can share posts on instagram, it is not possible using this api?
Unfortunatly the Graph API does not allow for actual posting of content
Hi Justin, was the type of app you created in the beginning a business app or a consumer app?
it is a consumer app
'Your app has standard access to public_profile. To use Facebook Login, switch public_profile to advanced access. Get Advanced Access;
This reply shows up in the settings part of the Facebook Login. If I don't grant advanced access, does that affect anything?
Why i get this error message: Undefined property: Facebook\Exceptions\FacebookSDKException::$getMessage in obtaining_access_token.php file
the answer is 'Graph returned an error ' . $e->getMessage(); and 'Facebook SDK returned an error ' . $e->getMessage();
now the error is Facebook SDK returned an error Cross-site request forgery validation failed. Required param "state" missing from persistent data.
@@MrTheripper7 with the persistent_data_handler set to session you should not need state. But, you can try adding a 'state' => 'value' to the creds array and see if that helps.
Hey, Thank you so much. Can you please let me know how add multiple images using excel
Hey! Thanks for watching, not sure about excel but you can check out my video on posting content which might help you out.
8:48 there is no instagram business account shown at my page. Why? I connected one to my Facebook page...
solved it by connecting a instagram account who exists for a while and not a fresh created account
Thanks for this video, but JFC, I cannot believe Facebook makes it so close to impossible to get a 60-day access token. Why can't we just request the token from our Facebook account dev settings? We have to be PHP experts, install their SDK, go through 5 access-token hurdles... WTF?! Why make it so difficult for web developers?
Yeah they don't make it easy and it sure is annoying!
Really nice video.
Is there anyway to post instagram using api?
Thanks! Posting to Instagram is currently in closed beta developers.facebook.com/docs/instagram-api/guides/content-publishing
How can I go about refreshing the access token? Should I do so every time I interact with the API, or would that be abuse?
everytime would be okay
I cannot login to the facebook app. I am stuck in the Valid Oauth Redirect URIs. How can I follow your tutorial without having my own website? I tried to use localhost but facebook doesn't allows me to do it.
Make sure your application is in development mode and localhost should work. You might also want to try https on localhost. I have a video for it ua-cam.com/video/lDRdewhH_vg/v-deo.html
Thanks a lot for this perfect video. I'm doing exactly same, but getting error "Call to a member function isLongLived() on null in..." after backing from linking and permitting app to facebook dialog.
Thanks I appreciate it :D Make sure you have $facebook initialized and try dumping out the facebook object along with the accesstoken object to see if you can spot any errors
@@justinstolpe thanks for help. Yes, the issue is depending on censoring facebook in my country. My host would not connecting to some facebook services :(
Thank you so much for these videos! Is it possible to use this API to send a Direct message to a user's PM? With triggers such as user likes a post, my app sends him a direct message.
The api does not allow for sending DM at this time.
@@justinstolpe Here's the thing though, I've seen a company's instagram post where if you liked it, you get a DM from them automatically. Manychat also allows you to do it for a fee. How did they do it?
hey i m new to this what text editor you r usinhg?
sublime text is the editor
Does this SDK work with the new API version?
yeah it should
Currently Instagram Graph Api and Basic Api cant be in 1 product then how do we use access token for graph api?
check out my new playlist on instagram graph api
what redirect urls can i use? yours isnt working
You can use localhost for testing, otherwise you will need to specify your actual domain with tthe path to your actual script where IG will redirect the user after they authenticate
I have business instagram account but it doesn't have facebook account. how do i get the access token?
The business IG account needs to be admin on a facebook page in order to connect.
sir I'm facing this error
"Invalid Scopes: manage_pages. This message is only shown to developers. Users of your app will ignore these permissions if present. Please read the documentation for valid permissions at: developers.facebook.com/docs/facebook-login/permissions ".
while redirecting to facebook for acess token ...
The manage_pages has been deprecated here is the docs on the new permissions developers.facebook.com/docs/pages/overview/permissions-features
I'm trying to generate a map of my instagram post's geolocation. Is this possible with the new APIs?
And also thank you! there are not many guides on Graph API!
@@beo1222 Thanks! I do not think you can get geolocation with the Graph API
@@justinstolpe is there any way to?
@@beo1222 I don't think so
Hi Justin. Thanks for your useful videos. When I get a token the expiresAt is Null in token object.Does it mean that long lived access token wont expire?if not, How can I refresh the long lived access token?
A user token will expire after 60 days if not refreshed. You can simply make a request to refresh the token. Check the api docs for refresh token details.
@@justinstolpe Thanks for your prompt reply. I checked the api docs but I couldn't find anything about refresh token. I'd be thankful if you could send me the link.
@@hodakhodabakhshi4164 developers.facebook.com/docs/facebook-login/access-tokens/refreshing/
@@justinstolpe If it expires at NULL, will it cause errors in the future?
@@JohnCaspino if it expires you need the user to reauthorize your app and get a new access token.
how to post images and videos on instagram account. Did you make any video regarding this. If yes then please share me link
The api currently does not allow for posting of images/videos.
@@justinstolpe Thanks for reply. Will this facility available in future?
@@dineshprajapati902 I am not sure it it will be, we will have to wait and see.
@Justin Stolpe we are getting instagram gram insights that is connected to our fb page but can we get insights from other's business accounts e.g.,getting monthly visitors of someone's business account?please help me i am stuck on this from half month 😢😢😢
To get insights on other accounts, that account needs to authenticate with your application.
@@justinstolpe according to documentation instagram accounts connected to fb page as admin ' s insights can be accessed and only 5 admins are allowed i want insight of every influencer who is loggedin to my website , if you help me i will gratefulfor you.
here is link to that guidelines
developers.facebook.com/docs/instagram-api/overview#pages
developers.facebook.com/docs/instagram-api/overview#tasks
does facebook and instagram use the same app id and secret ?
Yeah for the graph API you use the facebook client id and client secret from your app
Hi, when i click to "Login With Facebook" link in obtaining_access_token.php, Facebook shows me an error like that:
"Invalid Scopes: manage_pages. This message is only shown to developers. Users of your app will ignore these permissions if present. Please read the documentation for valid permissions at: developers.facebook.com/docs/facebook-login/permissions"
How can i fix it?
Is there anyone who can help me?
@@ibrahimsenn7 The manage_pages was replaced with six other permissions in late May developers.facebook.com/docs/permissions/reference/manage_pages/
How can I extend a long-lived user access token with Instagram Graph API without user interaction? Is using a short-lived access token (with a user interaction) the only way? I'd like to extend a long-lived user access token without user interaction.
On every call you make to the api you could try and refresh the token and save the new one. The only way to get the short lived token for a user is with interaction.
@@justinstolpe Thank you, Justin. I don't quite understand what you said. I have the long-lived user access token stored in a database. I use version 6.0 of the Instagram Graph API. When I refresh the long-lived user access token, the data_access_expires_at field continues with the same timestamp, it does not change. Is it possible to refresh the user access token with the long-lived user access token? I don't have a short-lived user access token.
@@franccallau1452 The tokens get updated once a day on facebooks end. They do not get refreshed each time you hit the endpoint which is why you see the same expiration time. Wait at least a day and you will see a new expiration date when you hit the endpoint.
I know this video is two years old and I'm wondering if that's the reason it doesn't work. When I click on Login to Facebook, I'm sent to FB, but instead of it opening a dialog box to sign into my account I get a 'Sorry, something went wrong.' page on Facebook. Any new current updates would be appreciated.
Not sure what the issue was but seems to work now when I try to login with my fb account and authorize my app.
Did you solve it?
Hi sir, currently it's not working. also I've checked your live demo, there have a blanked page. can you fix it?
Same here for me. Worked a few days ago but not today
@@Matthew-ld5zk I've tried all the ways. But I can't solve it
@@jihadhasan1151 Maybe your access token has expired? Hard to say though without knowing the exact error message the api is returning.
@@justinstolpe it's a access token generator script. so if i create first then it will be expired. By the way, When I download your github file and run it with my site then it's give me some error. of course I've changed app id and app secret
@@jihadhasan1151 There should be an error in the response which can help figure out what the issue is.
Thank you for the great tutorial. You said we can publish content using the API, but how? I searched UA-cam and all I found is how to get content not how to publish content?
You can't publish content with the API
@@justinstolpe Thank you for your reply. Is there any other ways to publish content? Any third party solutions?
@@SuperMa06 Possibly, but I don't know any
You find any solution?
@@nencypatel2354 publishing with the API is now possible, see ua-cam.com/video/1lKzu3UVJso/v-deo.html
can i extend my instagram graph api accessstoken with long live token for 60 days?
Yeah you can upgrade it to 60 days that is the max.
@@justinstolpe thanks justin!!
@@justinstolpe how can i get the url to extend the accesstoken?
everything zuckerberg touches gets to complicated lizard hell for developers
Is it posible to get ALL the comments from a post with the Graph API ? Thank you
Yeah, comments for a post come back in pages of 25 or 50 with a next/prev link to get the next/prev page of comments if there are many.
Justin Stolpe thank you so much!! And may I ask one more question? I have a rate limit of 200query/user/hour. So posts with 100k comments (25/query) are 4000 queries. Is the “next” query counting for the rate limit? Sorry for my english
@@jacintofleta I see, yeah I think it does count. If you go to your facebook app dashboard and click on the api rate limit usage meter, it will tell you the calls that you have made that count towards that rate limit.
Justin Stolpe thank you sooo much 🙏🏼
@Jacinto Fleta and @Justin Stolpe... The post that i want to get ALL the comments, can be from another user? Or only works for my posts?
Hello Justin, I am working on one social app where i have to track IG posts and stories of user. I am able to get IG posts via IG Graph API but i didn't get any API for IG Stories.
Flow: We have implemented Instagram Login at mobile app side and on successful login they are sharing IG access token to Backend(Node Js) where i am saving access token and when needed i am calling Graph API at my side to get Post. I want stories as well is there any way.
Hello Sumeet , do I need a domain owner to gain access? Because I don't have a "valid oauth redirect uris" address of my own. I would be very happy if you answer.
I do not think the API allows access to stories
@@berkayyurur If your app is live mode then you need a domain. You can use localhost with the app in development mode.
@@justinstolpe I just want an app to check my own Instagram account. For example, who deleted me etc. When I have problems, can I send you an e-mail? Because there is not enough Turkish resources. Thank you, so much.
@@berkayyurur If you want it to run on anything else besides localhost you will need a domain.
Hi Justin How can I extract any Facebook groups data.? Could you send me any API or tools. thanks
I have not used the api for groups before but might look into it in the future. Here is the link to the documentation developers.facebook.com/docs/groups-api/
And how can i get user_id?
In the next video I get the Instagram account id ua-cam.com/video/763kVf9fvqA/v-deo.html
I have used your code and when I click on the "Login with facebook" login button gating error bow like "Sorry, something went wrong." how to resole it? please helf me
Hmm not sure with that vague error, maybe double check your app is setup correctly and you are using the right creds.
Thank you , please we can get permission for post in fb groups
I will see what I can do! I am currently working on Instagram Graph API
Justin Stolpe thank you we can get full access token
Can i fetch other Instagram users followers count and media using this Instagram graph API
Is it necessary to have Instagram business account
@@parmar3112 You can switch your IG account from personal to business.
@hitesh suthar is it possible to get other users media and insight?
is there any sdk available for Python?
Not that I know of
@@justinstolpe thanks for replying 🙏
Are Facebook sdk and meta business sdk different?
@novartisnk9684 yeah for getting access tokens for a user you need to authenticate through fb login
Invalid Scopes: manage_pages. This message is only shown to developers. Users of your app will ignore these permissions if present. Please read the documentation for valid permissions at:
The manage_pages has been deprecated here is the docs on the new permissions developers.facebook.com/docs/pages/overview/permissions-features
Can you provide a tutorial on Instagram content publishing API
Instagram API does not have a publishing content endpoint
@@justinstolpe as of 26 jan 2021 they do have one
@@abhishekbaguldesign thanks for the update! I will make a tutorial for it then, been waiting for them to make the endpoint as lots of ppl have been asking about it!
content publishing video is up ua-cam.com/video/1lKzu3UVJso/v-deo.html
@@justinstolpe Thanks :)
Good video but you jump a lot of things that I really don't know where you get there! like the PHP file link, and after that I get lost for complete, not a good video for rookies that are trying to learn.
let me know, what PHP file link are you talking about? what else am I jumping that you do not know how to get? here to help :D
@@justinstolpe You jumped passed the part where you CD'd into a folder that you didn't mention up until that point. What folder?
@@thomasalias8492 cd into your web root directory to where your code is located. In my case I am in my www/blog_code/instagram_graph_api/ folder. Code is also on github :)
@@justinstolpe hi Justin, I totally agree with Giomar. I never worked with API in general and I need to learn how to use Instagram Graph API for a project, so I would like to ask you if you can make a video where you can explain in steps. Like Giomar mentioned you jump for example from 44 to 32 but I don't know why
Wow this api is quite obtuse... api review process is about the same feeling as getting sand rubbed in your eyes. I am not a happy camper at the moment...
yup...been there multiple times
this is great. but I wonder why I get Invalid Scopes: instagram_basic
Sounds like you need to add the permission so your app