-
Notifications
You must be signed in to change notification settings - Fork 199
Automatic renewal of OAuth2 token #779
Comments
In order to automatically renew the token you must have the client and the oauth2 saved in the system. If you save them with If the httr2 version is 0.2.3.9000 or higher it should automatically renew |
Thanks a lot! I have now tested it over multiple days and have been able to renew the token automatically with no problem as described :) |
Thanks for confirming it works well. |
Would you be able to share a bit more how you got this working @Rafael-Ayala? I saved the client and auth as instructed, do
It works for the first two hours but then 2 hours after that I get
With it opening a browser to get me to authenticate manually again. How does one get the auto-refresh to work? |
I'm closing this @guga31bb but you need the devel version of both httr2 and rtweet. |
My apologies for the late reply. As @llrs mentioned, you need those devel versions. client <- rtweet_client(clientID, clientSecret, "app_name")
oauth2 <- rtweet_oauth2(client)
client_save(client)
auth_save(oauth2, "name_fot_oauth2") Before the bot loop, and then the following in the bot loop: oauth2 <- rtweet:::auth_renew(oauth2) |
That last step, calling the internal function |
I see! I have not tried without it. I have just restarted my bot without that call. Will post here the results |
For what it's worth, I followed the exact steps above (without auth_renew) with rtweet 1.2.0.9003 and httr2 0.2.3.9000 and it still asks for an authorization code after 2 hours. So for anyone else reading this having problems getting it to work without manual intervension, you aren't alone!
|
Thanks for double checking. The joys of using an in-development version (which commit of httr2 are you using? check it out with I'll need to figure the way to do it with the upcoming release of httr2 (which seems closer, as there are a lot of commits recently). Hopefully this is resolved before httr2 update, which would mean I could release rtweet 1.3 to CRAN. |
I have now also verified that it does not work for me unless I place a explicit call to |
This is the most recent commit as of now. Sounds like I could get it to work by using the httr2 version that you both were using back in July, but obviously that's a short term fix (and not helpful to you!). Looking at the commit history of httr2 it does seem like the auth stuff is a moving target right now so probably makes sense to just wait until they finish. |
I am not sure if the problem has to do with using a more recent version of httr2. This is because I tested not placing a explicit call to |
Oh, thanks @Rafael-Ayala. Then the problem is in the logic rtweet uses to renew the credentials. Luckily today I have some surprise free time and I will look into it. If you can provide the trail/conditions about how this message appears I would appreciate it. I.e. if anyone can show the process from |
A bit more information if it's helpful- it's not just re-authorizing that is problematic with the current dev version of httr2. I can't even get it to authenticate in the first place:
In the browser (on twitter), I see
I should have mentioned this in the first place, but I never had authenticating working and assumed it was a problem on my end since it was working for you guys. So I was authenticating with an older version of httr2 and then trying to refresh credentials with the new version. But it seems clear now that there's an issue with a combination of the current versions of rtweet / httr2 |
I recently tested with the latest httr2 and the authentication part works even starting from a fresh installation. To re-authorize your app you might get asked each time via the browser to authenticate the app if too much time passed since last authentication. I'll plan to submit this week a new version to CRAN, any bug reports will be appreciated. |
That was me! r-lib/httr2#319 And thank you for the update |
Problem
Firstly, thanks a lot for the excellent package and all the efforts to maintain it.
I have read on the changelog (https://docs.ropensci.org/rtweet/news/index.html) that it should be possible to automatically renew OAuth2 tokens (required by the V2 API for posting tweets through tweet_post()). This would be required in order to set up a bot aiming just to post tweets every few hours (without collecting any data or interacting in any way with replies).
However, when I include in my code calls to auth_renew() every hour, I get the following error message when calling it on an expired OAuth2 token:
I would like to note that I manage to successfully post through tweet_post() using the free plan as long as I provide an OAuth2 token. But basically I would like to have to avoid to provide authorization manually every 2 hours to renew the token (if possible).
Expected behavior
I expected that it would just renew the token and enable continued bot operation.
Reproduce the problem
rtweet version
The text was updated successfully, but these errors were encountered: