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 refreshing without Heroku #654

Open
kaleidografik opened this issue Apr 14, 2020 · 26 comments
Open

Token refreshing without Heroku #654

kaleidografik opened this issue Apr 14, 2020 · 26 comments
Labels
feature request pinned Important discussions and announcements

Comments

@kaleidografik
Copy link

Hey guys, the V2 tutorial only gives us an option to refresh our tokens via the Heroku app. However, what about if we're not able to use Heroku. Is there an alternative? I'd really like to get an automated token refreshing process in place so as to ensure continued functionality.

@stevenschobert
Copy link
Owner

Thanks for the question!

The Heroku option is currently the only open-source option we have.

But I’d really love to see the community create alternative methods in various languages and open-source them so we could think them in the README. It’d be great to see supported options in Wordpress, .NET, etc.

@kaleidografik
Copy link
Author

Yes that would be super useful, at the moment I can't seem to find any information on how to refresh apart from via the command line, which is fine for the odd occasion but not very useful for a production environment.

@stevenschobert
Copy link
Owner

The process of getting and refreshing the access tokens is outlined in the Instagram Basic Display API docs: https://developers.facebook.com/docs/instagram-basic-display-api/guides/long-lived-access-tokens/

I think there is an example in there on using curl from the command line.

@benjamin-hull
Copy link
Collaborator

In general, a token refresh service would need to do the following things (this is assuming running on a server somewhere):

  • Accept and store a valid API token as a starting point
  • Periodically make a request to the IG refresh_token endpoint and update the current token value (every < 60 days)
  • Provide some way of serving the current token value to the page where instafeed is being run.

If this is running on the same server that is running the site you want to use instafeed on, then the simplest thing is to just include the token value in the page rendered by the server - that way there's no extra request to fetch the token, etc.

The Heroku option is really optimised for "works for most people, is free, requires next-to-no coding". It's by no means the best or most efficient way if you can do some server-side work!

@benjamin-hull
Copy link
Collaborator

I should also mention that we've been in contact with the developer of instant-tokens.com, which is another service designed to work with instafeed.js. As far as I know it does do everything needed, but it's centralised and not currently open-source, so I can't vouch for its security or suitability for a production environment. We'll update the readme if it that changes.

@kaleidografik
Copy link
Author

Hey guys, just wanted to follow up on this with our implementation, which may or may not be useful for others.

So, we register our account over at instant-tokens.com, which does the heavy lifting of refreshing the short lived token every 60 days. We then use a AJAX call to hit the supplied instant-tokens.com url (which returns the access token as JSON). We can then parse the JSON to target exactly what we need, in this case Token.

$.ajax({
    type: 'get',
    dataType: 'json',
    url: 'https://ig.instant-tokens.com/users/XXXXX/instagram/XXXXX/token?userSecret=XXXXX',

    success: function (response) {
        var feed = new Instafeed({
            target: 'carousel-instagram',
            accessToken: response.Token, // Access token from json response
    });
    feed.run();
});

@tyssen
Copy link

tyssen commented Jul 2, 2020

It's worth pointing out that as of a few days ago Heroku is now suspending instagram-token-agent apps immediately after they're created.

companionstudio/instagram-token-agent#13

@JonathanHo
Copy link

Hey guys, just wanted to follow up on this with our implementation, which may or may not be useful for others.

So, we register our account over at instant-tokens.com, which does the heavy lifting of refreshing the short lived token every 60 days. We then use a AJAX call to hit the supplied instant-tokens.com url (which returns the access token as JSON). We can then parse the JSON to target exactly what we need, in this case Token.

$.ajax({
    type: 'get',
    dataType: 'json',
    url: 'https://ig.instant-tokens.com/users/XXXXX/instagram/XXXXX/token?userSecret=XXXXX',

    success: function (response) {
        var feed = new Instafeed({
            target: 'carousel-instagram',
            accessToken: response.Token, // Access token from json response
    });
    feed.run();
});

Today I was getting suspended by Heroku immediately after deployment, so I switched to this method,
it worked quickly and well for me, thank you!

@t1mwillis
Copy link

t1mwillis commented Jul 11, 2020

Or, if you don't have jQuery on your site/don't want to add it, just do it using fetch! It is 2020 after all 😄

fetch('https://ig.instant-tokens.com/users/XXXXXX/instagram/XXXXXX/token?userSecret=XXXXX')
  .then(resp => resp.json())
  .then(data => {
    const feed = new Instafeed({
      accessToken: data.Token, // Access token from json response
    });
    feed.run();
  })
  .catch((error) => {
    console.log(error)
  });

@garethmorgans
Copy link

Thanks @t1mwillis & @kaleidografik

@codingbadger
Copy link

codingbadger commented Jul 28, 2020

Hello,

You can now link directly to a JS file using https://Instant-Tokens.com which automatically sets a JS variable named InstagramToken with your Instagram Access Token.

<script src="https://ig.instant-tokens.com/users/XXXXXX/instagram/XXXXXX/token.js?userSecret=XXXXX"></script>

codingbadger/instant-tokens.com#2

Full demo on both ways to access the token can be found here https://github.com/codingbadger/instant-tokens.com/wiki/3.-Instafeed.js-Demo

Cheers

Barry

@Matra-Simca
Copy link

Just very easily used Instant-Tokens.com - Unlike the Heroku method I wasn't required to go through Facebook developers, does that mean this method isn't limited to the 200 user per hour restrictions?

@codingbadger
Copy link

@Matra-Simca Instant-Tokens.com uses its own Facebook application so is still bound by the same rate-limiting rules however the limit is not a per-user limit it is calculated as 240 times the number of users.

Glad you had a good experience with instant-tokens.com :-)

@Matra-Simca
Copy link

Thanks @codingbadger - it's definitely a straightforward solution - sorry I'm still not clear in practial terms of how the rate-limiting works. Who is the user in this case, is it the end user viewing the feed, or the Instagram account linked to instant-tokens.com? Or have I misundertood completely!

Ideally I want to add two different configurations of Instafeed on different pages, it seems like this would require the same token being used in each case, so I'm wary of doubling the use rate if the practical limit is relatively low.

@codingbadger
Copy link

Instant-tokens.com is well below any rate-limiting being imposed by Instagram. As an example over 125,000 calls were made to the Instagram API via the Intstant-Tokens.com Application and it has really only scratched the surface of any limits.

@mikelivingston04
Copy link

Thanks @codingbadger - Instant-Tokens definitely seems to be the better solution. However, I cannot get it to work in my actual application. It works fine and appears to be working correctly for me within a codepen, but I get the error Uncaught Error: Error from Instagram: The access_token provided is invalid. in the console. The token is populating correctly, and again, all looks to be working correctly in Codepen, but i'm not sure why it wouldn't work within my own website. Any thoughts?

@codingbadger
Copy link

codingbadger commented Jul 29, 2020 via email

@mikelivingston04
Copy link

@codingbadger

Here is the issue: codingbadger/instant-tokens.com#6.

Not sure why the coding formatting didn't work for my code. My apologies.

@stale
Copy link

stale bot commented Nov 5, 2020

This issue has been automatically marked as stale because it hasn't had new comments in the last 3 months. It will be closed if no further activity occurs. If you still need assistance with this issue, or believe it shouldn't be closed, please respond with a new comment to let us know.
Thank you all for your contributions.

@stale stale bot added the stale Issues that have been inactive for 90 days or more label Nov 5, 2020
@stevenschobert stevenschobert added the pinned Important discussions and announcements label Nov 12, 2020
@stale stale bot removed the stale Issues that have been inactive for 90 days or more label Nov 12, 2020
@sudip-modi
Copy link

Thank you so much everyone. Finally integrated Instagram on my site🙏.

@FreMun
Copy link

FreMun commented Mar 13, 2021

A few days before I would release a website for a client, this happened: Facebook has disabled the Instant Tokens Application

Any alternative would appreciated!

@kaleidografik
Copy link
Author

A few days before I would release a website for a client, this happened: Facebook has disabled the Instant Tokens Application

Any alternative would appreciated!

This is such a shame, hopefully @codingbadger can get the service back up and running shortly.

@codingbadger
Copy link

The Instant Tokens Application has been reinstated by Facebook after an appeal.

@abdullahoguk
Copy link

abdullahoguk commented Jun 22, 2022

I made a simple node.js script that refresh set of tokens. You can run the script with github actions to refresh them regularly.
This is an example repo that refresh in 3 days interval. Interval can be changed in workflow file (.github/workflows/tokenRefresh.yml). and token list can be specified in tokens.js.

https://github.com/abdullahoguk/refresh-instagram-tokens

@kris-g
Copy link

kris-g commented Sep 9, 2022

I made a simple node.js script that refresh set of tokens. You can run the script with github actions to refresh them regularly. This is an example repo that refresh in 3 days interval. Interval can be changed in workflow file (.github/workflows/tokenRefresh.yml). and token list can be specified in tokens.js.

https://github.com/abdullahoguk/refresh-instagram-tokens

Is this working? I can only see the log file date being updated every 3 days. The tokens.js hasn't been updated since the initial commit.

@abdullahoguk
Copy link

@kris-g
Yes It's working. The tokens itself is not changing. tokens.js is a list of tokens to be reissued for batch refreshing purpose. When I debug the token, it says issued on Wednesday (3 days ago). I updated the readme for usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request pinned Important discussions and announcements
Projects
None yet
Development

No branches or pull requests