來自Molx的解決方案似乎不再有效。這個問題似乎在於
api.url <- paste0("https://api.twitter.com/1.1/lists/members.json?slug=",
twlist, "&owner_screen_name=", twowner, "&count=5000")
這個URL似乎對我嘗試的任何twlist或twowner都不是有效的。 編輯:這個問題來自於身份驗證我想我得到
{"errors":[{"code":215,"message":"Bad Authentication data."}]}
我覺得我驗證這個
## Twitter authentication,
consumer_key = "xxxxx"
consumer_secret = "xxx"
access_token = "xxxxx"
access_secret = "xxx"
setup_twitter_oauth(consumer_key, consumer_secret, access_token,
access_secret)
來自哪裏的問題?
編輯:當我進入get_oauth_sig()
我得到以下
> twitteR:::get_oauth_sig()
<Token>
NULL
<oauth_app> twitter
key: XXXXXXX
secret: <hidden>
<credentials> oauth_token, oauth_token_secret
---
結果是這正常嗎?
Molx的解決方案似乎不再有效。這個問題似乎在於
api.url <- paste0("https://api.twitter.com/1.1/lists/members.json?slug=",
twlist, "&owner_screen_name=", twowner, "&count=5000")
這個URL似乎對我嘗試的任何twlist或twowner都不是有效的。 編輯:這個問題來自於身份驗證我想我得到
{"errors":[{"code":215,"message":"Bad Authentication data."}]}
我覺得我驗證這個
## Twitter authentication,
consumer_key = "xxxxx"
consumer_secret = "xxx"
access_token = "xxxxx"
access_secret = "xxx"
setup_twitter_oauth(consumer_key, consumer_secret, access_token,
access_secret)
來自哪裏的問題?
編輯:當我進入get_oauth_sig()
我得到以下
> twitteR:::get_oauth_sig()
<Token>
NULL
<oauth_app> twitter
key: XXXXXXX
secret: <hidden>
<credentials> oauth_token, oauth_token_secret
---
結果是這正常嗎?
編輯:我通過GET
library(rjson)
library(twitteR)
consumer_key = "xxxxx"
consumer_secret = "xxx"
access_token = "xxxxx"
access_secret = "xxx"
setup_twitter_oauth(consumer_key, consumer_secret, access_token,
access_secret)
https://twitter.com/ivalerio/lists/justice?lang=fr
twlist <- "d-put-s-2017-2022"
twowner <- "ivalerio"
api.url <- paste0("https://api.twitter.com/1.1/lists/members.json?slug=",
twlist, "&owner_screen_name=", twowner, "&count=5000")
response <- GET(api.url, config(token=twitteR:::get_oauth_sig()))
#Count = 5000 is the number of names per result page,
# which for this case simplifies things to one page.
# This returns a JSON response which we can read using fromJSON:
response.list <- fromJSON(content(response, as = "text", encoding = "UTF-8"))
# Now, we have a list where each element is the Twitter data of one Twitter-list member. To extract their names and user_names:
users.names <- sapply(response.list$users, function(i) i$name)
users.screennames <- sapply(response.list$users, function(i) i$screen_name)
# Which are:
head(users.names)
感謝這麼多的極好註釋的答案更換POST解決問題。正如你所說,它打開了很多信息。什麼是找出列表和子列表中可用元素的最佳方式,例如name,screen_name – pssguy
我正在使用'names(response.list)'來檢查內容是什麼,然後'names(response.list $ users )',等等。 'str(response.list)'也適用,但如果嵌套列表太多,可能會很難理解。 – Molx
是'str(response.list)'是少數。但是,我得到了'NULL'響應'names(response.list $ users)' – pssguy