Handling multiple tokens

10 views
Skip to first unread message

Andrea De Angelis

unread,
Sep 11, 2017, 2:47:20 PM9/11/17
to rtweet

Hi,

I follow all the instructions on Obtaining and using access tokens.
This works fine with one token, but says little about how do I handle more than one token?

I have two different purposes and I would like to switch e.g. to twitter_token2 when twitter_token1 runs out of rate limits.
Should I set multiple TWITTER_PATH locations in the .Renviron file?
E.g.:

TWITTER_PATH1=/Users/myname/twitter_token.rds
TWITTER_PATH2=/Users/myname/twitter_token2.rds
....

However, rtweet:::twitter_pat() only seems to look at Sys.getenv("TWITTER_PAT"), or files like twitter_tokens etc…

My question is about the best way to set up a routine such as the following:

  1. tmp.limit <- rate_limit(token=NULL, query="followers(ids))
  2. if (tmp.limit$remaining !=0) { <DO STUFF>}
  3. else { <SWITCH TOKEN AND DO OTHER STUFF> }

Is there a way I can implement this in a straightforward way?

Thank you.
Andrea

Reply all
Reply to author
Forward
0 new messages