minimal twitter API call using R

Step 1 : Follow steps 1-4 as mentioned in https://moebiuscurve.wordpress.com/2014/10/12/calling-twitter-apis-using-curl/

Step 2: Start an R session and execute the following one by one(provide your own consumerKey and consumerSecret).

consumerKey<-“zNHUyLyV9jWeZ3gaEPUryBuxg”
consumerSecret<-“VA9LTDjAFDkEEYZ6E2UScNlQJeZiEz6uonu7xGIdNnJ7cshAzj”

requestURL=https://api.twitter.com/oauth/request_token

accessURL=https://api.twitter.com/oauth/access_token

authURL=https://api.twitter.com/oauth/authorize

options( RCurlOptions = list(verbose = TRUE, ssl.verifyhost=FALSE, ssl.verifypeer=FALSE))
cred<-OAuthFactory$new(consumerKey=consumerKey,consumerSecret=consumerSecret, requestURL=requestURL, accessURL=accessURL, authURL=authURL)
cred$handshake()

registerTwitterOAuth(cred)
bigdata<-searchTwitter(“#bigdata”,n=50)

 

The session will look something like below. (The user commands are written in italics, while system output is in bold)

> library(twitteR)
Loading required package: ROAuth
Loading required package: RCurl
Loading required package: bitops
Loading required package: digest
Loading required package: rjson
> consumerKey<-“zNHUyLyV9jWeZ3gaEPUryBuxg”
> consumerSecret<-“VA9LTDjAFDkEEYZ6E2UScNlQJeZiEz6uonu7xGIdNnJ7cshAzj”
> options( RCurlOptions = list(verbose = TRUE, ssl.verifyhost=FALSE, ssl.verifypeer=FALSE))
> cred<-OAuthFactory$new(consumerKey=consumerKey,consumerSecret=consumerSecret,requestURL=https://api.twitter.com/oauth/request_token,accessURL=https://api.twitter.com/oauth/access_token,authURL=https://api.twitter.com/oauth/authorize)
> cred$handshake()
* Hostname was NOT found in DNS cache
*   Trying 199.59.148.87…
* Connected to api.twitter.com (199.59.148.87) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
* WARNING: failed to load NSS PEM library libnsspem.so. Using OpenSSL PEM certificates will not work.
* skipping SSL peer certificate verification
* SSL connection using TLS_RSA_WITH_AES_128_CBC_SHA
* Server certificate:
*     subject: CN=api.twitter.com,OU=Twitter Security,O=”Twitter, Inc.”,L=San Francisco,ST=California,C=US
*     start date: Aug 03 00:00:00 2014 GMT
*     expire date: Dec 31 23:59:59 2016 GMT
*     common name: api.twitter.com
*     issuer: CN=VeriSign Class 3 Secure Server CA – G3,OU=Terms of use at https://www.verisign.com/rpa (c)10,OU=VeriSign Trust Network,O=”VeriSign, Inc.”,C=US
> POST /oauth/request_token HTTP/1.1
Host: api.twitter.com
Accept: */*
Content-Length: 216
Content-Type: application/x-www-form-urlencoded

* upload completely sent off: 216 out of 216 bytes
< HTTP/1.1 200 OK
< cache-control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0
< content-length: 126
< content-security-policy: default-src https:; connect-src https:; font-src https: data:; frame-src https:; img-src https: data:; media-src https:; object-src https:; script-src ‘unsafe-inline’ ‘unsafe-eval’ https:; style-src ‘unsafe-inline’ https:; report-uri https://twitter.com/i/csp_report?a=NVXW433SMFUWY%3D%3D%3D&ro=false;
< content-type: text/html; charset=utf-8
< date: Thu, 13 Nov 2014 20:04:06 UTC
< etag: “b3be31e10b9da7549c76afe47a0bfad5”
< expires: Tue, 31 Mar 1981 05:00:00 GMT
< last-modified: Thu, 13 Nov 2014 20:04:06 GMT
< pragma: no-cache
* Server tsa_a is not blacklisted
< server: tsa_a
< set-cookie: _twitter_sess=BAh7BzoPY3JlYXRlZF9hdGwrCNV4wapJAToHaWQiJTVlNTcxNDkxMzk2ZTE1%250ANTUxN2UzODg1YjJmMThjYWQy–7ceccc5dd195e8c9b9813731a95d941c8592b058; domain=.twitter.com; path=/; secure; HttpOnly
< set-cookie: guest_id=v1%3A141590904647518894; Domain=.twitter.com; Path=/; Expires=Sat, 12-Nov-2016 20:04:06 UTC
< status: 200 OK
< strict-transport-security: max-age=631138519
< vary: Accept-Encoding
< x-connection-hash: d4b5c2938501787180cc70407c8fa405
< x-content-type-options: nosniff
< x-frame-options: SAMEORIGIN
< x-mid: 91e05ac849e88e1adf2c1d5057c6a3426e173042
< x-runtime: 0.01647
< x-transaction: 9248728380539516
< x-ua-compatible: IE=edge,chrome=1
< x-xss-protection: 1; mode=block
<
* Connection #0 to host api.twitter.com left intact
To enable the connection, please direct your web browser to:
https://api.twitter.com/oauth/authorize?oauth_token=8PBb2Qh3k0jtfsSkEiNVNil7rUlfKzuS

When complete, record the PIN given to you and provide it here: 1270997
* Hostname was NOT found in DNS cache
*   Trying 199.59.148.87…
* Connected to api.twitter.com (199.59.148.87) port 443 (#1)
* WARNING: failed to load NSS PEM library libnsspem.so. Using OpenSSL PEM certificates will not work.
* skipping SSL peer certificate verification
* SSL connection using TLS_RSA_WITH_AES_128_CBC_SHA
* Server certificate:
*     subject: CN=api.twitter.com,OU=Twitter Security,O=”Twitter, Inc.”,L=San Francisco,ST=California,C=US
*     start date: Aug 03 00:00:00 2014 GMT
*     expire date: Dec 31 23:59:59 2016 GMT
*     common name: api.twitter.com
*     issuer: CN=VeriSign Class 3 Secure Server CA – G3,OU=Terms of use at https://www.verisign.com/rpa (c)10,OU=VeriSign Trust Network,O=”VeriSign, Inc.”,C=US
> POST /oauth/access_token HTTP/1.1
Host: api.twitter.com
Accept: */*
Content-Length: 271
Content-Type: application/x-www-form-urlencoded

* upload completely sent off: 271 out of 271 bytes
< HTTP/1.1 200 OK
< cache-control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0
< content-length: 170
< content-security-policy: default-src https:; connect-src https:; font-src https: data:; frame-src https:; img-src https: data:; media-src https:; object-src https:; script-src ‘unsafe-inline’ ‘unsafe-eval’ https:; style-src ‘unsafe-inline’ https:; report-uri https://twitter.com/i/csp_report?a=NVXW433SMFUWY%3D%3D%3D&ro=false;
< content-type: text/html; charset=utf-8
< date: Thu, 13 Nov 2014 20:06:35 UTC
< etag: “fde7210a4938f90107a68292c9534538”
< expires: Tue, 31 Mar 1981 05:00:00 GMT
< last-modified: Thu, 13 Nov 2014 20:06:35 GMT
< pragma: no-cache
* Server tsa_a is not blacklisted
< server: tsa_a
< set-cookie: _twitter_sess=BAh7BzoPY3JlYXRlZF9hdGwrCFi9w6pJAToHaWQiJWQzNWZkODNmMTUyOTk2%250AMmNjYTBlNjk5MGM1MWVmNjNk–d10cb7ef6a7618db4ebff3c1a03c77a6bc3a4b7a; domain=.twitter.com; path=/; secure; HttpOnly
< set-cookie: guest_id=v1%3A141590919508868817; Domain=.twitter.com; Path=/; Expires=Sat, 12-Nov-2016 20:06:35 UTC
< status: 200 OK
< strict-transport-security: max-age=631138519
< vary: Accept-Encoding
< x-connection-hash: 7d64ecd4fbb59aaa41cb9796627bf79e
< x-content-type-options: nosniff
< x-frame-options: SAMEORIGIN
< x-mid: 79529459162722fc627edf1b9f0b19715819e26f
< x-runtime: 0.08348
< x-transaction: e454ce30fec0592f
< x-ua-compatible: IE=edge,chrome=1
< x-xss-protection: 1; mode=block
<
* Connection #1 to host api.twitter.com left intact
> registerTwitterOAuth(cred)
[1] TRUE
> bigdata<-searchTwitter(“#bigdata”,n=50)
* Hostname was NOT found in DNS cache
*   Trying 199.59.148.87…
* Connected to api.twitter.com (199.59.148.87) port 443 (#2)
* WARNING: failed to load NSS PEM library libnsspem.so. Using OpenSSL PEM certificates will not work.
* skipping SSL peer certificate verification
* SSL connection using TLS_RSA_WITH_AES_128_CBC_SHA
* Server certificate:
*     subject: CN=api.twitter.com,OU=Twitter Security,O=”Twitter, Inc.”,L=San Francisco,ST=California,C=US
*     start date: Aug 03 00:00:00 2014 GMT
*     expire date: Dec 31 23:59:59 2016 GMT
*     common name: api.twitter.com
*     issuer: CN=VeriSign Class 3 Secure Server CA – G3,OU=Terms of use at https://www.verisign.com/rpa (c)10,OU=VeriSign Trust Network,O=”VeriSign, Inc.”,C=US
> GET /1.1/search/tweets.json?q=%23bigdata&include_entities=TRUE&result_type=recent&count=50&oauth_nonce=6luTBgt5jUBkHPkOJnmXS&oauth_timestamp=1415909296&oauth_token=2852508895-0cE4251jy0ZKrs2lDR0LvCT8BSc2R9N6hSl6yIm&oauth_consumer_key=zNHUyLyV9jWeZ3gaEPUryBuxg&oauth_signature_method=HMAC-SHA1&oauth_version=1.0&oauth_signature=dMIGof%2F15z2ti5qhW6vFj5KLiQM%3D HTTP/1.1
Host: api.twitter.com
Accept: */*

< HTTP/1.1 200 OK
< cache-control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0
< content-length: 255990
< content-type: application/json;charset=utf-8
< date: Thu, 13 Nov 2014 20:08:17 UTC
< expires: Tue, 31 Mar 1981 05:00:00 GMT
< last-modified: Thu, 13 Nov 2014 20:08:17 GMT
< pragma: no-cache
* Server tsa_a is not blacklisted
< server: tsa_a
< set-cookie: lang=en
< set-cookie: guest_id=v1%3A141590929762964978; Domain=.twitter.com; Path=/; Expires=Sat, 12-Nov-2016 20:08:17 UTC
< status: 200 OK
< strict-transport-security: max-age=631138519
< x-access-level: read-write
< x-connection-hash: 57404d8909522adaa7cf8c94542f5c8f
< x-content-type-options: nosniff
< x-frame-options: SAMEORIGIN
< x-rate-limit-limit: 180
< x-rate-limit-remaining: 178
< x-rate-limit-reset: 1415909334
< x-transaction: 88622aecd62f9f27
< x-xss-protection: 1; mode=block
<
* Connection #2 to host api.twitter.com left intact
> head(bigdata)
[[1]]
[1] “itknowingness: RT @BigDataExpo: [slides] @CoryIsaacson @BigDataExpo Presentation | Building an Agile #BigData Infrastructure ▸ http://t.co/tT95zSMbP1 #Clo…”

[[2]]
[1] “SDDCexpo: RT @BigDataExpo: [slides] @CoryIsaacson @BigDataExpo Presentation | Building an Agile #BigData Infrastructure ▸ http://t.co/tT95zSMbP1 #Clo…”

[[3]]
[1] “SYSCONmedia: RT @BigDataExpo: [slides] @CoryIsaacson @BigDataExpo Presentation | Building an Agile #BigData Infrastructure ▸ http://t.co/tT95zSMbP1 #Clo…”

[[4]]
[1] “Gdecorso60: RT @wef: Is data the key to saving energy? #wef #techpioneers http://t.co/tB9XX8aFpP #greentech @burnfromprep #bigdata http://t.co/6PaJxPnR…&#8221;

[[5]]
[1] “WATT_emPOWER: RT @OSSLine: TIBCO and Ericsson form Global OSS/BSS Partnership – http://t.co/TqfgNXQOar #bssoss #bigdata”

[[6]]
[1] “SOAWorldExpo: RT @BigDataExpo: [slides] @CoryIsaacson @BigDataExpo Presentation | Building an Agile #BigData Infrastructure ▸ http://t.co/tT95zSMbP1 #Clo…”

About moebiuscurve

I have too many interests to keep me occupied for a lifetime
This entry was posted in Uncategorized and tagged . Bookmark the permalink.

Leave a comment