0

我编写了以下脚本来从 twitter 中提取推文。

library("twitteR")
library("ROAuth")
library("RCurl")
library("httr")
download.file(url="http://curl.haxx.se/ca/cacert.pem",destfile="cacert.pem")
ck <- '4QPOQJoiBgoGP7jU13Akxfp2E'
cs <- 'ued02VUpial3K8NW8foectZj1UFtsEfQetQJbYXD21uCj0ohJc'
ak <- '136316586-xWnCMrE5UYSzigTOwTVyR4NH4gfR01adpR5SF5IK'
as <- 'zsIj4lsDc5xKcDyofWkYijKnUY8Uj71sg1NfaIFKZbGc2'
reqURL<- 'https://api.twitter.com/oauth/request_token'
acURL <- 'https://api.twitter.com/oauth/access_token'
auURL <- 'https://api.twitter.com/oauth/authorize'
cred <- OAuthFactory$new(consumerKey=ck,consumerSecret=cs,requestURL=reqURL,accessURL=acURL,authURL=auURL)
cred$handshake(cainfo="cacert.pem")
save(cred, file="twitter_authentication.Rdata")
load("twitter_authentication.Rdata")
oauth_endpoints("twitter")
myapp <- oauth_app("twitter",key=ck,secret=cs)
twitter_token <- oauth1.0_token(oauth_endpoints("twitter"), myapp)
setup_twitter_oauth(ck,cs)
search.string <- "#Bahubali"
no.of.tweets <- 10
tweets <- searchTwitter(search.string, n=no.of.tweets, lang="en")
tweets
write.csv(tweets, file='/home/horopter/tweet/CSVTweets.csv', row.names=F)

但是我得到了这个 setup_twitter_oauth(ck,cs) [1] "Using browser based authentication" Waiting for authentication in browser... Press Esc/Ctrl + C to abort

我被困在那里。网站要么显示“您没有权限”。或者根本打不开。如果我不提供回调 url,它就不会进行身份验证,否则会再次卡住,如上所述。帮帮我。

4

1 回答 1

0

我曾经尝试使用相同的代码和身份验证令牌,这是对我有用的代码。setup_twitter_oauth需要所有ck, cs, ak, as参数。

library("twitteR")
library("ROAuth")
library("RCurl") 
library("httr")
download.file(url="http://curl.haxx.se/ca/cacert.pem",destfile="cacert.pem")
ck <- '4QPOQJoiBgoGP7jU13Akxfp2E'
cs <- 'ued02VUpial3K8NW8foectZj1UFtsEfQetQJbYXD21uCj0ohJc'
ak <- '136316586-xWnCMrE5UYSzigTOwTVyR4NH4gfR01adpR5SF5IK'
as <- 'zsIj4lsDc5xKcDyofWkYijKnUY8Uj71sg1NfaIFKZbGc2'
setup_twitter_oauth(ck,cs, ak, as)
search.string <- "#Bahubali"

下载文件后,这应该设置您的身份验证.pem。当它要求进行身份验证时,请按 1。

于 2015-07-17T01:54:34.053 回答