Problem in getting Twitter data using Rstudio


Hello everyone,

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


credential <- OAuthFactory$new(consumerKey="AAAA",

download.file(url="", destfile="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 = "", destfile = "cacert.pem") :
  downloaded length 251894 != reported length 251894

Plz help me


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?


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.


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.


Let check and get back to you


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.


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?


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