8

我在 AWS“Ubuntu Server 12.04.2 LTS”上运行 R Studio,并通过我的浏览器访问 R Studio。

当我尝试使用ROAuth带有代码的包在 Twitter API 上进行身份验证时:

credential<-OAuthFactory$new(consumerKey="xxxxx",
                             consumerSecret="xxxxx",
                             requestURL="https://api.twitter.com/oauth/request_token",
                             accessURL="https://api.twitter.com/oauth/access_token",
                             authURL="https://api.twitter.com/oauth/authorize")

credential$handshake()
registerTwitterOAuth(credential)

registerTwitterOAuth(credential)说完后我得到一个错误

  Error in registerTwitterOAuth(credential) : 
  ROAuth is no longer used in favor of httr, please see ?setup_twitter_oauth

但是我找不到任何进一步的解释..

4

5 回答 5

6

显然,在我发布之前,twitteR 包已更改,因此新的身份验证方法是

setup_twitter_oauth(CUSTOMER_KEY, CUSTOMER_SECRET, ACCESS_TOKEN, ACCESS_secret, credentials_file=NULL)

https://github.com/geoffjentry/twitteR

于 2013-08-28T20:17:28.133 回答
1

我遇到了一些setup_twitter_oauth()功能问题。我运行了以下代码,它对我有用,没有任何错误。

library(RCurl)
require(twitteR)
library(ROAuth)
reqURL <- "https://api.twitter.com/oauth/request_token"
accessURL <- "https://api.twitter.com/oauth/access_token"
authURL <- "https://api.twitter.com/oauth/authorize"
api_Key <-  "XXXXXXX"
api_Secret <- "XXXXXXXXXXXXXXXXX"

twitCred <- OAuthFactory$new(consumerKey=api_key,
                            consumerSecret=api_secret,
                            requestURL=reqURL,
                            accessURL=accessURL,
                            authURL=authURL
)
twitCred$handshake()

编辑:

刚刚对我的应用程序 access_token 的问题进行了排序,现在setup_twitter_oauth功能运行良好。

api_key如果您的, api_secret, acsess_token,access_token_secret生成时没有错误,请尝试以下代码使用 R 进行 Twitter 身份验证。

api_key = "XXXXXXXXX" // your api_key
api_secret = "XXXXXXXXXX" // your api_secret 
access_token = "XXXXXXXXXX" // your access_token 
access_token_secret = "XXXXXXXXXX" // your access_token_sceret 
setup_twitter_oauth(api_key,api_secret,access_token,
                     access_token_secret)
于 2015-11-03T10:11:53.013 回答
1

以下对我有用:

packages <- c("twitteR","ROAuth")#"openssl","base64enc"
### checking if packages are already installed and installing if not
check.install.load.Package<-function(package_name){
  if(!package_name%in%installed.packages()){
    install.packages(package_name)
  }
  library(package_name,character.only = TRUE)
}
for(package in packages){
  check.install.load.Package(package)
}


api_key = "XX" # your api_key
api_secret = "XX" # your api_secret 
access_token = "XX" # your access_token 
access_token_secret = "XX" # your access_token_sceret 
credential<-OAuthFactory$new(consumerKey=api_key,
                             consumerSecret=api_secret,
                             requestURL="https://api.twitter.com/oauth/request_token",
                             accessURL="https://api.twitter.com/oauth/access_token",
                             authURL="https://api.twitter.com/oauth/authorize")

credential$handshake()

setup_twitter_oauth(api_key,api_secret,access_token,
                    access_token_secret)



search.string <- "#RohingyaTerrorReality"
no.of.tweets <- 60

RohingyaTerrorReality.Tweets <- searchTwitter(search.string, n=no.of.tweets,lang="en",)



df <- do.call("rbind", lapply(RohingyaTerrorReality.Tweets, as.data.frame))
View(df)
于 2017-09-13T20:10:00.030 回答
1

这是对我有用的 R 脚本:

 library("twitteR")
 library("ROAuth")

download.file(url= "http://curl.haxx.se/ca/cacert.pem", destfile= "cacert.pem")
credentials <- OAuthFactory$new(consumerKey='XXXXXXXXXXXXXXXXXX',
  consumerSecret='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
  requestURL='https://api.twitter.com/oauth/request_token',
  accessURL='https://api.twitter.com/oauth/access_token',
  authURL='https://api.twitter.com/oauth/authorize')

credentials$handshake(cainfo="cacert.pem")

save(credentials, file="twitter authentication.Rdata")

load("twitter authentication.Rdata")

setup_twitter_oauth(credentials$consumerKey, credentials$consumerSecret, 
credentials$oauthKey, credentials$oauthSecret)
于 2018-10-27T01:40:20.440 回答
0

我在使用 setup_twitter_oauth 函数时遇到了一些问题。在运行 setup_twitter_oauth 函数或加载凭据文件后,我运行以下代码并没有获得对象。

然后我只加载 cred_1.RData 文件,我得到一个似乎没有用的 sig objetc。

我在 Windows 上并安装了包的 github 版本。

rm(list = ls(,all=T))


setwd("D:\\TWEETS\\cuenta_1")
library(twitteR)
library(httr)

# Credenciales

consumer_key =   "xxxxxxxxxxxxxxxx"
consumer_secret = "xxxxxxxxxxxxxxxx"
access_token = "xxxxxxxxxxxxxxxxxxx"
access_secret = "xxxxxxxxxxxxxxxx"

credentials_file = "cred_1.RData"

setup_twitter_oauth(consumer_key, consumer_secret, access_token, access_secret, credentials_file)
load_twitter_oauth("cred_1.RData")

ls()

> ls()
[1] "access_secret"    "access_token"     "consumer_key"     "consumer_secret" 
[5] "credentials_file"


> load("cred_1.RData")
> 
> ls()
[1] "access_secret"      "access_token"       "consumer_key"       "consumer_secret"    "credentials_file"   "load_twitter_oauth" "set_oauth_sig"     
[8] "sig"               
> 
> print(sig)
Config: 
List of 1
 $ signature:function (method, url)  
于 2013-11-04T21:57:46.220 回答