Problem in getting Twitter data using Rstudio


#1

Hello everyone,

I am trying to access twitter data using R on Windows via the following steps:

library(bitops)
library(RCurl)
library(RJSONIO)
library(twitteR)
library(ROAuth)


credential <- OAuthFactory$new(consumerKey="AAAA",
                   consumerSecret="BBBB",
                   requestURL="https://api.twitter.com/oauth/request_token",
                   accessURL="https://api.twitter.com/oauth/access_token",
                   authURL="https://api.twitter.com/oauth/authorize")

download.file(url="http://curl.haxx.se/ca/cacert.pem", destfile="cacert.pem")

credential$handshake(cainfo="cacert.pem")

But every time I get this message:

Error: Authorization Required

What I have done to find a solution:

  1. I spent countless hours trying almost everything I found on web!
  2. Created a new App
  3. Tested my App on my friend laptop and it worked for him!
  4. Tried to access twitter via Linux (also did not work)

P.s. When I tried to download the “cacert.pem” files, I got the following warning message:

Warning message:
In download.file(url = "http://curl.haxx.se/ca/cacert.pem", destfile = "cacert.pem") :
  downloaded length 251894 != reported length 251894

Plz help me


#2

This looks like an oAuth issue. Given that there are no Access Key/Secret it looks like you are trying to do App only Authentication? What resource are you trying to access?


#3

You should download cacert.pem once and package it with your code. If you download it live it can be MITMed to include any TLS certs an attacker wants and your future requests are all compromised. Plus significantly improve performance by avoiding unnecessary network requests.


#4

I am trying to access twitter data.

actually there is a access Key/Secret. I refer to them by “consumerKey” and “consumerSecret” in the credential line.


#5

Let check and get back to you


#6

Hello Abraham,

thank you for your help, and I want to assure you that I only ran the download.file function once, and downloaded cecert.pem directly prior to attempting to use the API, but I still get the error.


#7

I understood this, but what data exactly?
And if you are referring to Access Key/Secret as Consumer Key and Consumer Secret, where are your actual consumer key and consumer secret then?


#8

I just want to pull some data (i.e. some twitties on #cars).
Regarding my Access Key/Secret, I just hided them in this post for security reasons.
And just to add on top of this, I’m using the twitter app Access Key/Secret NOT token Key/Secret