我正在关注几年前在Stack Overflow thread上提供的代码,但是当我运行' fromJSON'时出现错误。命令,"代码86,此方法需要GET或HEAD"。我试图从公共Twitter列表(所有NHL播放器)获取用户名列表。
这是代码
# load packages
library("twitteR")
library("rjson")
library("httr")
consumer_key <- "XXX"
consumer_secret <- "XXX"
access_token <- "XXX"
access_secret <- "XXX"
options(httr_oauth_cache=T)
setup_twitter_oauth(consumer_key, consumer_secret, access_token, access_secret)
twlist <- "nhl-players"
twowner <- "NHL"
api.url <- paste0("https://api.twitter.com/1.1/lists/members.json?slug=",
twlist, "&owner_screen_name=", twowner, "&count=500")
response <- POST(api.url, config(token=twitteR:::get_oauth_sig()))
fromJSON(content(response, as = "text", encoding = "UTF-8"))
答案 0 :(得分:1)
我想我已经明白了。您的api.url
对象中有一个小错字。它不是“&amp; NHL =”(这是实际值),它是“&amp; owner_screen_name =”(这是您要传递的参数的名称)。另外,您需要使用GET请求。
api.url <- paste0("https://api.twitter.com/1.1/lists/members.json?slug=", twlist, "&owner_screen_name=", twowner, "&count=500")
response <- GET(api.url, config(token=twitteR:::get_oauth_sig()))
答案 1 :(得分:0)
对于那些和我一样吵架的人。这是现在可以使用的代码:
api.url <- paste0("https://api.twitter.com/1.1/lists/members.json?slug=", twlist, "&owner_screen_name=", twowner, "&cursor=-1&count=1000")
response <- GET(api.url, config(token = twitteR:::get_oauth_sig()))
如您所见,您需要添加&cursor=-1