使用 API 每次调用加载多个问题 ID
Using API to load more than one question ids per call
使用带有来自 SO 的问题 ID 的数据框:
df <- data.frame (qid = c(71663375, 71674701, 71724524))
使用以下代码可以进行 3 api 次调用以接收每个问题的信息。
然而,SO 应用程序提供了 运行 调用 100 个 ID 的机会。怎么做到的?
library(stackr)
for (j in 1:nrow(df)) {
questions <- stack_questions(df$qid[j])
}
如果 app
一次可以处理 100 个,split
qid
到 list
个向量中,每个 list
元素一次处理 100 个时间,
lst1 <- split(df$qid, as.integer(gl(nrow(df), 100, nrow(df))))
然后使用lapply
library(stackr)
out <- lapply(lst1, stack_questions)
out_dat <- do.call(rbind, out)
或for
循环遍历list
out <- vector('list', length(lst1))
for(i in seq_along(lst1)) {
out[[i]] <- stack_questions(lst1[[i]])
}
out_dat <- do.call(rbind, out)
-输出
> out
[[1]]
tags is_answered view_count accepted_answer_id answer_count score last_activity_date creation_date last_edit_date question_id content_license
1 r TRUE 32 71724636 1 0 2022-04-03 04:32:10 2022-04-03 04:15:43 2022-04-03 04:23:59 71724524 CC BY-SA 4.0
2 r TRUE 19 71674900 1 0 2022-03-30 04:38:41 2022-03-30 04:25:06 2022-03-30 04:32:58 71674701 CC BY-SA 4.0
3 sql,dataexplorer FALSE 27 NA 1 0 2022-03-29 09:18:20 2022-03-29 08:54:52 2022-03-29 09:00:36 71663375 CC BY-SA 4.0
link title
1 Melt a dataframe using a list column
2 Create a new column using detecting the domain of a url from an existing column
3 Paginate pages to receive results from tSQL
owner_account_id owner_reputation owner_user_id owner_user_type owner_profile_image owner_display_name
1 24733596 5 18621268 registered https://lh3.googleusercontent.com/a/AATXAJwQRtIYRrvKJi1a4AfvTHoE4ht8f_WQ1Qv3jtbr=k-s256 Domin D
2 24733596 5 18621268 registered https://lh3.googleusercontent.com/a/AATXAJwQRtIYRrvKJi1a4AfvTHoE4ht8f_WQ1Qv3jtbr=k-s256 Domin D
3 24733596 5 18621268 registered https://lh3.googleusercontent.com/a/AATXAJwQRtIYRrvKJi1a4AfvTHoE4ht8f_WQ1Qv3jtbr=k-s256 Domin D
owner_link
1 https://whosebug.com/users/18621268/domin-d
2 https://whosebug.com/users/18621268/domin-d
3 https://whosebug.com/users/18621268/domin-d
数据
df <- data.frame (qid = c(71663375, 71674701, 71724524))
使用带有来自 SO 的问题 ID 的数据框:
df <- data.frame (qid = c(71663375, 71674701, 71724524))
使用以下代码可以进行 3 api 次调用以接收每个问题的信息。
然而,SO 应用程序提供了 运行 调用 100 个 ID 的机会。怎么做到的?
library(stackr)
for (j in 1:nrow(df)) {
questions <- stack_questions(df$qid[j])
}
如果 app
一次可以处理 100 个,split
qid
到 list
个向量中,每个 list
元素一次处理 100 个时间,
lst1 <- split(df$qid, as.integer(gl(nrow(df), 100, nrow(df))))
然后使用lapply
library(stackr)
out <- lapply(lst1, stack_questions)
out_dat <- do.call(rbind, out)
或for
循环遍历list
out <- vector('list', length(lst1))
for(i in seq_along(lst1)) {
out[[i]] <- stack_questions(lst1[[i]])
}
out_dat <- do.call(rbind, out)
-输出
> out
[[1]]
tags is_answered view_count accepted_answer_id answer_count score last_activity_date creation_date last_edit_date question_id content_license
1 r TRUE 32 71724636 1 0 2022-04-03 04:32:10 2022-04-03 04:15:43 2022-04-03 04:23:59 71724524 CC BY-SA 4.0
2 r TRUE 19 71674900 1 0 2022-03-30 04:38:41 2022-03-30 04:25:06 2022-03-30 04:32:58 71674701 CC BY-SA 4.0
3 sql,dataexplorer FALSE 27 NA 1 0 2022-03-29 09:18:20 2022-03-29 08:54:52 2022-03-29 09:00:36 71663375 CC BY-SA 4.0
link title
1 Melt a dataframe using a list column
2 Create a new column using detecting the domain of a url from an existing column
3 Paginate pages to receive results from tSQL
owner_account_id owner_reputation owner_user_id owner_user_type owner_profile_image owner_display_name
1 24733596 5 18621268 registered https://lh3.googleusercontent.com/a/AATXAJwQRtIYRrvKJi1a4AfvTHoE4ht8f_WQ1Qv3jtbr=k-s256 Domin D
2 24733596 5 18621268 registered https://lh3.googleusercontent.com/a/AATXAJwQRtIYRrvKJi1a4AfvTHoE4ht8f_WQ1Qv3jtbr=k-s256 Domin D
3 24733596 5 18621268 registered https://lh3.googleusercontent.com/a/AATXAJwQRtIYRrvKJi1a4AfvTHoE4ht8f_WQ1Qv3jtbr=k-s256 Domin D
owner_link
1 https://whosebug.com/users/18621268/domin-d
2 https://whosebug.com/users/18621268/domin-d
3 https://whosebug.com/users/18621268/domin-d
数据
df <- data.frame (qid = c(71663375, 71674701, 71724524))