Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Token gets invalid #5

Closed
PregOfficial opened this issue May 4, 2020 · 14 comments
Closed

Token gets invalid #5

PregOfficial opened this issue May 4, 2020 · 14 comments
Labels
bug Something isn't working

Comments

@PregOfficial
Copy link

After a certain time my token turns invalid and doesn't refresh. Do I have to configure something in the Facebook Developer Console (something like the Valid OAuth Redirect URIs)?

@cbashleywoodford
Copy link

I have experienced a similar issue this morning. I've been getting this console error: api request error: 4 Application request limit reached

Sorry to hihjack your question Preg, just thought it would be nice to kill two birds with one stone.

@cbashleywoodford
Copy link

@benjamin-hull any idea when you will be able to take a look into this?

@benjamin-hull
Copy link
Member

Hi @awoodford - I think your issue is a separate one (hitting the API request limit). There's a fairly simple workaround on the FB/IG side - I put some details in the wiki: https://github.com/companionstudio/instagram-token-agent/wiki/Instagram-API-Limits

@benjamin-hull
Copy link
Member

@PregOfficial, that's an interesting one.

If you have help pages enabled on your app (they are enabled by default), you should be able to visit (your-app-name).herokuapp.com to check the status: The token agent will fetch your most recent post, and also show the time that Temporize is due to refresh your token.

Would you check that page and report back what it says?

@benjamin-hull benjamin-hull added the bug Something isn't working label May 12, 2020
@cbashleywoodford
Copy link

cbashleywoodford commented May 12, 2020

Hi @benjamin-hull thanks for your reply.

I've add 2 new testers to the app but still seeing the same issue.

I am also seeing this message on the Heroku app page now:
image

Any ideas? Thanks

@PregOfficial
Copy link
Author

Thanks for your reply @benjamin-hull, it was my fault. I assigned a short lived token instead of a long lived. This one expired after an hour and didn't refresh.

@PregOfficial
Copy link
Author

@awoodford I wrote a detailed instruction for me, how to set up the token and the token agent. If you want, I can share it with you.

@cbashleywoodford
Copy link

@PregOfficial Thank you that would be great - it would be interesting to see. Although i've not had any issues setting it up it just hits the API call limit and adding new test users didn't fix that.

Either way that would be very much appreciated thank you :)

@PregOfficial
Copy link
Author

This is my instruction to set up the token and the agent

  1. Facebook Console
  2. Create new App
  3. Add a Product -> Instagram
  4. Roles
    1. Roles -> add Instagram Testers
    2. search for the Account and add it
    3. go to https://www.instagram.com/accounts/manage_access/
    4. Tester Invites
    5. accept Invite
  5. Go To
    https://www.instagram.com/oauth/authorize?client_id={app-id}&redirect_uri={redirect-uri}&scope=user_profile,user_media&response_type=code
  6. Click Authorize App
    1. Redirect to given URL
    2. URL Param ?code=..., this code will be used to generate a short-lived access token
  7. Use code without #_ for cURL
    curl -X POST \
      https://api.instagram.com/oauth/access_token \
      -F client_id={app-id} \
      -F client_secret={app-secret} \
      -F grant_type=authorization_code \
      -F redirect_uri={redirect-uri} \
      -F code={code without #_}
    Result is a short-lived access token
  8. Generate a long-lived access token
     curl -i -X GET "htts://graph.instagram.com/access_token
      ?grant_type=ig_exchange_token
      &client_secret={app-secret}
      &access_token={short-life-access-token}"

Use the long-lived access token to set up the agent.

Hope this helps

@cbashleywoodford
Copy link

@PregOfficial Thats awesome thank you!

@benjamin-hull
Copy link
Member

Hey guys - and thanks @PregOfficial!

There is a simpler method to replace steps 5-8, and you can get a long-lived token directly from the app dashboard, with instructions here: https://developers.facebook.com/docs/instagram-basic-display-api/overview#user-token-generator

@cbashleywoodford
Copy link

@benjamin-hull that's how i've done it.

I've added 2 new testers and still getting the same issue. Removing the main tester account (where I'm getting the images from) and adding it again get's it working again.

Any ideas?

@PregOfficial
Copy link
Author

@benjamin-hull - with the facebook instructions my token turned invalid, but with the more complex method it worked.

@benjamin-hull
Copy link
Member

benjamin-hull commented May 12, 2020

Okay - so re-reading the documentation, I understand now that the 'adding extra users' workaround will not work, because the Basic Display API uses User Access Tokens, rather than Application Access Tokens which use a shared pool.

Unfortunately, according to the docs, user-level call limits are not a hard, published number:

Due to privacy concerns, we do not reveal actual call count values for users.

So - this leaves us with a problem. The Basic Display API always authorizes as a single user, and that user has a limited but unknown number of calls they can make per hour.

The 'real' answer to this issue (and I think the one Facebook/Instagram intends people to use), is to process these requests server-side, and cache the results before delivering them to user's browsers. That way the number of requests is 1 * number of feed refreshes per hour not 1 * number of feed refreshes per hour * number of page views per hour.

I will check in with a contact at Facebook to see if there's any other possible solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants