I am trying to use twitteR. I already have my keys and everything but I always get the following error:
Error in check_twitter_oauth() : OAuth authentication error:
This most likely means that you have incorrectly called setup_twitter_oauth()'
The code is the following:
library(twitteR)
# open json file
keys <- fromJSON(file = "path")
# keys
consumerKey <- keys$Key
consumerSecret <- keys$Secret
accessToken <- keys$Token
accessTokenSecret <- keys$TokenS
# connect to twitter
setup_twitter_oauth(consumerKey, consumerSecret, access_token=accessToken, access_secret=accessTokenSecret)
Why do I get the error?
Thanks
Related
I have set up my Twitter API
consumerKey <- "xx"
consumerSecret <- "xx"
accessToken <- "xx"
accessTokenSecret <- "xx"
setup_twitter_oauth(consumerKey, consumerSecret, accessToken, accessTokenSecret)
This was returned (which has been successful before)
[1] "Using direct authentication"
Now, when I am trying to stream tweets for a certain amount of time, it seems to be successful as its running but it returns the file under values and not under data and shows "NULL"
btw21test <- stream_tweets("#BTW21",
timeout = (60*5),
parse = FALSE,
file_name = "BTW21.json"
)
## read in JSON file
btw21test <- parse_stream("BTW21.json")
NULL
Does anyone know if this is because of the Twitter API? I have used the exact same code successfully in the past. Thanks!
I am very new to downloading tweets from R. I want to download tweets automatically in a day and I wrote the following code
`key <- "xx"
cons_secret <- "xx"
token <- "xx"
access_secret <- "xx"
my_token <- setup_twitter_oauth(key, cons_secret, token, access_secret)
BIST <- "BIST"
stream_tweets( "BIST", timeout = 60,
parse = FALSE, token=my_token)`
this code did not work,
I got this error
Error in readRDS(x) : error reading from connection
I also want to download them to json output in.
Is my code true? How can I handle this?
Thanks.
library(httr)
library(httpuv)
library(jsonlite)
myapi <- oauth_app("github", "0b23485d6d6e55143372",
secret = "xxxxxxxxxxxxxxxxxxxxxxx")
github_token <- oauth2.0_token(oauth_endpoints("github"), myapi)
request1 <- GET("https://api.github.com/users/jtleek/repos", config(token = github_token))
myjson <- content(request1)
myjson2 <- jsonlite::fromJSON(toJSON(myjson))
View(myjson2)
stop_for_status(request1)
#
I use R 3.2.5 and Win7 32 bit.
There are 2 problems. One is after the final line of code, I got an error Error: Unauthorized (HTTP 401).
And the second is when I tried to see what the github_token is,
<Token>
<credentials> error, error_description, error_uri
#
Finally myjson2 is not a dataframe but just a list
$message
[1] "Bad credentials"
$documentation_url
[1] "https://developer.github.com/v3"
I've had the same issue, so I have created a new set of key and secret on github page. By the way, I don't think you need to convert using jsonlite::, the format should be fine. I used the following:
gtoken <- config(token = github_token)
req <- with_config(gtoken, GET("https://api.github.com/users/jtleek/repos"))
con_req <- content(req)
find_create <- function(x,myurl) {
if (x$html_url == myurl) {
print(x$created_at)
}
}
lapply(con_req,find_create,myurl ="https://github.com/jtleek/datasharing")
I am trying to a R script through command line which connects to twitter. When I run the code through R-Studio it is able to connect to twitter and get the tweets. However when I run the script through command line I get the following error:
Error: oauth_listener() needs an interactive environment.
To resolve this, I ran once through R-studio and saved the environment variables in the following manner:
if(file.exists("./token_file"))
{
load("./token_file")
}
else
{
token <- setup_twitter_oauth(consumerKey,consumerSecret,access_token=NULL, access_secret=NULL)
save(token,file="./token_file")
}
Now I get an error:
Error in get_oauth_sig() : OAuth has not been registered for this session
I tried saving the authentication session as well by:
requestURL <- "https://api.twitter.com/oauth/request_token"
accessURL <- "https://api.twitter.com/oauth/access_token"
authURL <- "https://api.twitter.com/oauth/authorize"
if(file.exists("./auth_file"))
{
load("./auth_file")
}
else
{
my_oauth <- OAuthFactory$new(consumerKey = consumerKey, consumerSecret = consumerSecret,
requestURL = requestURL, accessURL = accessURL, authURL = authURL)
save(my_oauth,file ="./auth_file")
}
However I still get the above mentioned error. Is there a way to get R to connect to twitter through command line?
I am using twitteR package.
I search for stream in twitter by using the function
searchTwitter("love", n=10)
I believe you need to use a different authentication model than the interactive login. I'm not an expert on these things unfortunately but it seems that from the Twitter documentation you want "Application-only authentication".
https://dev.twitter.com/oauth/application-only
I am trying to register an OAuth token and I am running into an error that doesn't seem to be explained anywhere I can find.
require("ROAuth")
require("twitteR")
requestURL <- "https://api.twitter.com/oauth/request_token"
accessURL <- "http://api.twitter.com/oauth/access_token"
authURL <- "http://api.twitter.com/oauth/authorize"
Here is where I would plug in my consumer key and consumer secret which I obtained properly.
consumer_key <- "XXXXXXXXXXXXXXXXXXXXX"
consumer_secret <- "YYYYYYYYYYYYYYYYYYYYY"
This is the first attempt:
twitCred <- OAuthFactory$new(consumerKey = consumer_key, consumerSecret = consumer_secret, requestURL = requestURL,
accessURL = accessURL, authURL = authURL)
But I get the following error:
Error in get(name, envir = asNamespace(pkg), inherits = FALSE) :
object '.setDummyField' not found
Other posts suggested I use the following:
getTwitterOAuth(consumer_key, consumer_secret)
But I get the same error. I can't seem to find the error reproduced anywhere else which is making me suspect it has nothing to do with the twitteR or ROAuth packages. I'm new to these so any advice on how to fix the error is greatly appreciated.
I had the same problem. The following sequence of commands solved the problem:
consumerKey <- ...
consumerSecret <- ...
twitCred <- getTwitterOAuth(consumer_key= consumerKey, consumer_secret=consumerSecret)
searchTwitter()
Notice I didn't use registerTwitterOAuth(twitCred). I think if you wanna save and later load twitCred you have to use registerTwitterOAuth(twitCred) after loading.
I hope this helps.
As is mentioned in the question:
Other posts suggested I use the following:
getTwitterOAuth(consumer_key, consumer_secret)
But I get the same error.
So pbahr's answer wouldn't have helped I take it?
I was getting the same issue using both OAuthFactory$new and getTwitterOAuth but fixed it when I upgraded my R version from 3.0.0 to 3.0.2
I'm not sure if the version is the main cause of the issue but upgrading it worked for me.