instafeed.js icon indicating copy to clipboard operation
instafeed.js copied to clipboard

Token refreshing without Heroku

Open kaleidografik opened this issue 5 years ago • 31 comments
trafficstars

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.

kaleidografik avatar Apr 14 '20 13:04 kaleidografik

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.

stevenschobert avatar Apr 14 '20 14:04 stevenschobert

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.

kaleidografik avatar Apr 14 '20 14:04 kaleidografik

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.

stevenschobert avatar Apr 14 '20 14:04 stevenschobert

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 avatar Apr 14 '20 14:04 benjamin-hull

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.

benjamin-hull avatar Apr 14 '20 14:04 benjamin-hull

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();
});

kaleidografik avatar Jun 19 '20 08:06 kaleidografik

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.

https://github.com/companionstudio/instagram-token-agent/issues/13

tyssen avatar Jul 02 '20 04:07 tyssen

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!

JonathanHo avatar Jul 02 '20 14:07 JonathanHo

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)
  });

t1mwillis avatar Jul 11 '20 04:07 t1mwillis

Thanks @t1mwillis & @kaleidografik

garethmorgans avatar Jul 27 '20 10:07 garethmorgans

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>

https://github.com/codingbadger/instant-tokens.com/issues/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

codingbadger avatar Jul 28 '20 08:07 codingbadger

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?

Matra-Simca avatar Jul 28 '20 16:07 Matra-Simca

@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 :-)

codingbadger avatar Jul 28 '20 16:07 codingbadger

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.

Matra-Simca avatar Jul 29 '20 10:07 Matra-Simca

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.

codingbadger avatar Jul 29 '20 13:07 codingbadger

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?

mikelivingston04 avatar Jul 29 '20 18:07 mikelivingston04

Can you raise an issue in https://github.com/codingbadger/instant-tokens.com/issues and provide the sample code.

Thanks


From: mikelivingston04 [email protected] Sent: Wednesday, July 29, 2020 7:32:14 PM To: stevenschobert/instafeed.js [email protected] Cc: Barry Mooring [email protected]; Mention [email protected] Subject: Re: [stevenschobert/instafeed.js] Token refreshing without Heroku (#654)

Thanks @codingbadgerhttps://github.com/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?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/stevenschobert/instafeed.js/issues/654#issuecomment-665830209, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAIKAXBXAHXVOAKKC2QQOILR6BTK5ANCNFSM4MHX7MQA.

codingbadger avatar Jul 29 '20 18:07 codingbadger

@codingbadger

Here is the issue: https://github.com/codingbadger/instant-tokens.com/issues/6.

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

mikelivingston04 avatar Jul 29 '20 18:07 mikelivingston04

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[bot] avatar Nov 05 '20 02:11 stale[bot]

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

sudip-modi avatar Dec 06 '20 11:12 sudip-modi

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!

FreMun avatar Mar 13 '21 19:03 FreMun

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.

kaleidografik avatar Mar 13 '21 20:03 kaleidografik

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

codingbadger avatar Mar 14 '21 13:03 codingbadger

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

abdullahoguk avatar Jun 22 '22 14:06 abdullahoguk

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.

kris-g avatar Sep 09 '22 22:09 kris-g

@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.

abdullahoguk avatar Sep 10 '22 04:09 abdullahoguk