I'm trying to download some tweets using TwitteR API when connected to my VPN, but the issue is that I keep on getting the couldn't connect to host error when doing the handshake.
I've tried several things like:
But nothing seems to work, do you have any idea of what I can do to get it work?
Thanks in Advance.Code:
#Use below libraries:
require(twitteR) #twitteR Lib
require(httr) #httr Lib
require(ROAuth)
#Not Working
#Set Proxy so we can crawl twitter while connected to VPN
#Sys.setenv(http_proxy="XXXXXXXXXXXXXXX")
#options(shinyapps.http = "internal")
#$options(RCurlOptions = list(proxy = "XXXXXXXXXXXXXXXXX")
#h <- getCurlHandle(
#proxy = "XXXXXX",
#proxyport = XXX, cainfo = "cacert.pem")
l_consKey <- "XXXXXXXXXXXXXXX";
l_consSecret <- "XXXXXXXXXXXXXXX";
l_reqURL <- "https://api.twitter.com/oauth/request_token"
l_accessURL <- "https://api.twitter.com/oauth/access_token"
l_authURL <- "https://api.twitter.com/oauth/authorize"
#Download cacert.pm file
download.file( url = "http://curl.haxx.se/ca/cacert.pem", destfile = "cacert.pem");
#Manage OAuth Authentication
twitCredentials <- OAuthFactory$new( consumerKey = l_consKey
, consumerSecret = l_consSecret
, requestURL = l_reqURL
, accessURL = l_accessURL
, authURL = l_authURL
)
#Handshake
twitCredentials$handshake(cainfo="cacert.pem")
Thanks for your response. I already had both the library from github and the proxy option set. What I was missing was the setconfig option in my script:
Thanks a'lot!
Script:
###########################################################
#
# Libraries
#
###########################################################
library(twitteR); # Twitter API
library(httr); # httr library to set proxy options
###########################################################
#
# Variables
#
###########################################################
#Twitter API
l_consKey <- yourConsumerKeyHere;
l_consSecret <- yourConsumerSecret;
l_token <- yourConsumerAccessToken;
l_tokenSecret <- yourConsumerAccessTokenSecret;
#httr
l_proxyUrl <- yourProxyUrl
l_proxyPort <- yourProxyPortNumber
###########################################################
#
# Body
#
###########################################################
# Set proxy options
set_config( use_proxy( url = l_proxyUrl
, port = l_proxyPort
)
);
#OAuth authentication
setup_twitter_oauth( consumer_key = l_consKey
, consumer_secret = l_consSecret
, access_token = l_token
, access_secret = l_tokenSecret
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.