skip to Main Content

I am using the Twitter REST API to retrieve data in JSON format. Twitter’s developer page makes it easy by providing a command that can be pasted directly into the terminal and executed. The following command works in the terminal.

 curl --get 'https://api.twitter.com/1.1/statuses/user_timeline.json' --data 'count=3200&screen_name=BernieSanders' --header 'Authorization: OAuth oauth_consumer_key="####", oauth_nonce="####", oauth_signature="####", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1467719924", oauth_token="####", oauth_version="1.0"' --verbose

I am trying to get the JSON data into R, and would like to execute this same command in the R console. I have tried curlconverter using the exact same code, get an error that there is an unexpected symbol. However, the code is exactly the same. Is there a more suitable package for executing this code?

curlExample <- "curl --get 'https://api.twitter.com/1.1/statuses/user_timeline.json' --data 'count=3200&screen_name=BernieSanders' --header 'Authorization: OAuth oauth_consumer_key="####", oauth_nonce="####", oauth_signature="####", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1467719924", oauth_token="####", oauth_version="1.0"' --verbose"

2

Answers


  1. I think you are going to need to escape those quotation marks. Try this instead:

    curlExample <- "curl --get 'https://api.twitter.com/1.1/statuses/user_timeline.json' --data 'count=3200&screen_name=BernieSanders' --header 'Authorization: OAuth oauth_consumer_key="####", oauth_nonce="####", oauth_signature="####", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1467719924", oauth_token="####", oauth_version="1.0"' --verbose"
    

    That the quotes were not being escaped properly was actually evident in your question, because the Stack Overflow markup rendered the curlExample string in multiple colors.

    Login or Signup to reply.
  2. I believe https://cran.r-project.org/web/packages/twitteR/twitteR.pdf is the way to do this in R.

    But specifically in your case, you have unescaped ” in your string.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search