Search code examples
rtwittertwitter-oauth

TwitteR setup_twitter_oauth() gives an error


I am using twitteR package for the first time. The setup_twitter_oauth function gives me an error:

[1] "Using browser based authentication"
Error in curl::curl_fetch_memory(url, handle = handle) : 
Couldn't connect to server

or

[1] "Using browser based authentication" Error in
init_oauth1.0(self$endpoint, self$app, permission =
self$params$permission, : Bad Request (HTTP 400).

My code:

library(dplyr)
library(purrr)
library(twitteR)


setup_twitter_oauth(getOption("twitter_consumer_key"),
                    getOption("twitter_consumer_secret"),
                    getOption("twitter_access_token"),
                    getOption("twitter_access_token_secret"))

I am using Rstudio and Windows 7 with a proxy.


Solution

  • I believe the problem is that you're literally passing in those strings as arguments to setup_twitter_oath. They should be replaced by access tokens that Twitter gives you when you register your app.

    You can assign the actual credentials to objects like

    my_key, my_secret, my_access_token, my_access_secret

    and then connect like this:

    setup_twitter_oauth(my_key, my_secret, my_access_token, my_access_secret)
    

    I noticed that if I try to connect with no credential or fake credentials that I get the same error you were experiencing from setup_twitter_oauth.

    Make sure not to quote those objects or they're considered literal character strings.