可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I am following the latest update on twitteR homepage, and I can't pass the authorization process.
library(devtools)
install_github("twitteR", username="geoffjentry")
library(twitteR)
api_key <- "XXXXXXXXXXXXXXXXX"
api_secret <- "XXXXXXXXXXXXXXXXX"
access_token <- "XXXXXXXXXXXXXXXXX"
access_secret <- "XXXXXXXXXXXXXXXXX"
setup_twitter_oauth(api_key, api_secret, access_token, access_secret)
This is the output I am getting back:
[1] "Using direct authentication"
Error in check_twitter_oauth() : OAuth authentication error:
This most likely means that you have incorrectly called setup_twitter_oauth()'
I have also tried setup_twitter_oauth(api_key, api_secret)
, and this is the error message:
[1] "Using browser based authentication"
Error in init_oauth1.0(endpoint, app, permission = params$permission) :
client error: (401) Unauthorized
I don't think there are any other options in setup_twitter_oauth
. Does anyone else encounter this error?
回答1:
set callback url to http://127.0.0.1:1410 in app settings in twitter
回答2:
This error happens when your app is missing the callback url. To solve this issue go to https://apps.twitter.com/ select your application and then go to SETTINGS scroll down to CALLBACK URL and enter ( http://127.0.0.1:1410 ). This should allow you to run browser verification.
Or you can enter the access_token and access_secret in R to trigger local verification.
consumer_key <- " YOUR CONSUMER KEY "
consumer_secret<- " YOUR CONSUMER SECRET "
access_token <- " YOUR ACCESS TOKEN "
access_secret <- " YOUR ACCESS SECRET "
setup_twitter_oauth(consumer_key, consumer_secret, access_token, access_secret)
回答3:
I have tried setting call back URL to ( http://127.0.0.1:1410 ), updating all packages related to this package. Nothing solved my problem.
then i installed httk httpuv packages and did the lines below:
consumer_key <- " YOUR CONSUMER KEY "
consumer_secret<- " YOUR CONSUMER SECRET"
setup_twitter_oauth(consumer_key, consumer_secret,
access_token=NULL, access_secret=NULL)
It worked like a beauty.
Doing the above takes to a web page and you manually authorize the app.
While this may not be the solution to the question, it is definitely a workaround to the authentication roadblock.
回答4:
try install.packages('base64enc')
. it worked for me. found it in github discussion.
回答5:
I had the same problem. Tried all the suggestions I found on the net but in vain.
Probably it has to do with the Callback URL, I had skipped it earlier.
Created a new app, this time included it - http://127.0.0.1:1410 and it worked for me.
Here is the code I used:
library(httr)
library(devtools)
library(twitteR)
library(base64enc)
consumer_key <- 'XXXXXXXXXXXX'
consumer_secret <- 'XXXXXXXXXXXX'
access_token <- 'XXXXXXXXXXXX'
access_secret <- 'XXXXXXXXXXXX'
setup_twitter_oauth(consumer_key , consumer_secret, access_token, access_secret)
tw <- searchTwitter("LFC",n=100,lang="en")
Hope it helps.
回答6:
I faced the same problem and tried all latest httr download and libraries but still the problem was there. Then I created a new APP in twitter and used API keys and other credentials in the code and now the problem solved.
I was using an APP which i created 8 months back ....regenerating the API credentials may also solve for the existing APP.
回答7:
Try using this
setup_twitter_oauth(apiKey, apiSecret, access_token = accessToken, access_secret = accessSecret)
回答8:
I got it fixed by manually generating access token at apps.twitter.com site and pass that as argument to the api which will force to use local authentication rather than browser authentication.
回答9:
I encountered the same error:
"Error in check_twitter_oauth() : OAuth authentication error:
This most likely means that you have incorrectly called setup_twitter_oauth()'"
and after trying the different solutions posted here in the stackoverflow, I still did not get the problem solved. I have regenerated my consumer key and consumer secret and supplied it to the following lines in my R script:
consumer_key <- 'XXconsumer_keyXX'
consumer_secret <- 'XXconsumer_secretXX'
access_token <- 'XXaccess_tokenXX'
access_secret <- 'XXaccess_secretXX'
setup_twitter_oauth(consumer_key , consumer_secret, access_token, access_secret)
What I did to get it right and get the OAuth authentication handshake is to supply the twitter supplied consumer key, consumer secret, access token, access secret value directly to the 5th line above, that is,
setup_twitter_oauth("xxconsumer_key_xx", "xxconsumer_secretxx", "xxaccess_tokenxx", "xxaccess_secretxx")
This works for me and hope it will for you.
回答10:
I also had this issue and went through everything posted here to no avail. I finally looked at Windows Firewall and realized I had not made an exception for Rstudio. Everything works now!