pradel / node-instagram

Instagram api client for node that support promises.
MIT License
190 stars 27 forks source link

how to save the accesstoken ? #140

Closed helxsz closed 4 years ago

helxsz commented 6 years ago

This code works well, however when the accesstoken is retrieved, how would I save the accesstoken into the instagram instance.

I think

  instagram.config.accessToken = data.access_token ;

probably works.

Another question, how long does instagram access token would be valid, do i need to refresh the access token periodically ?

const instagram = new Instagram({
  clientId: 'clientId',
  clientSecret: 'clientSecret',
  accessToken: 'user-access-token',
});

const app = express();

app.get('/auth/instagram', (req, res) => {
  res.redirect(instagram.getAuthorizationUrl(redirectUri, { scope: ['basic'] }));
});

app.get('/auth/instagram/callback', async (req, res) => {
  try {
    const data = await instagram.authorizeUser(req.query.code, redirectUri);
    // access_token in data.access_token
     res.json(data);
  } catch (err) {
    res.json(err);
  }
});
penguoir commented 5 years ago

For your second question, Instagram doesn't refresh the token. However, they say you should re-auth the user once in a while. They probably advise this just to prevent liability or something.

pradel commented 4 years ago

I am closing the issues in this repo: The legacy Instagram API is deprecated and will be disabled on June 29, 2020. More information instagram.com/developer.