简体   繁体   中英

PHP Instagram api getting “code” and refreshing when authenticated

HI'm trying to figure out how authentication works. I got my Instagram authenticated, and then it redirects me to a "callback" or "redirect_uri". When I get redirected everything works like its supposed to. I get a ?code=54325114 like its supposed to.

But why when I refresh, its like I'm not authenticated anymore? I can't retrieve data. And when I go back to my index php (before authentication), I get redirected again and then the code changes, and it works again, but when I refresh, it doesn't again.

What is the correct way that I handle this situation?

Thanks, hopefully my scenario makes sense.

I appear to be a bit late to the party, but anyway.

When you authenticate a user with the IG API, you are sent an auth code. This code is only valid once. When you get this code, you must request the access token, which you can use many times. When you get the code, you should immediately get the access token and cache it (either as a session variable or cookie). Then, if the user reloads the page you should check if there is an access token already cached and if there is you should not attempt to regenerate it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM