"This method requires a GET or HEAD" 使用 twitteR、rjson、httr 时出错
"This method requires a GET or HEAD" error using twitteR, rjson, httr
我正在遵循几年前 上提供的代码,但是当我 运行 'fromJSON' 命令 "Code 86, This method requires a GET or HEAD" 时出现错误。我正在尝试从 public 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"))
我想我明白了。您的 api.url
对象中有一点错字。它不是“&NHL=”(这是实际值),它是“&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()))
献给像我一样苦苦挣扎的人。这是现在有效的代码:
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
我正在遵循几年前
这是代码
# 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"))
我想我明白了。您的 api.url
对象中有一点错字。它不是“&NHL=”(这是实际值),它是“&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()))
献给像我一样苦苦挣扎的人。这是现在有效的代码:
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