gpt4 book ai didi

r - 使用bigquery时,tidyverse API OAuth token 到期之前增加时间?

转载 作者:行者123 更新时间:2023-12-03 16:18:25 24 4
gpt4 key购买 nike

using bigrquery from R时,tidyverse API会要求进行身份验证,一旦提供身份验证,就可以从R session 访问bigquery。下载结果可能很耗时,并且如果oauth token 在传输过程中过期,则下载将失败:

Error: Invalid Credentials [authError]



范例程式码
# install.packages("tidyverse"); install.packages('bigrquery')
Sys.setenv(BIGQUERY_TEST_PROJECT="your-gcp-project-id")
library(tidyverse)
library(dbplyr)
library(bigrquery)

billing <- bq_test_project()

connection <- dbConnect(
bigrquery::bigquery(),
project = "your-gcp-project-id",
dataset = "dataset-name",
billing = billing
)

mytable <- tbl(connection, "mytable")

mytable %>%
-- some heavy dplyr wrangling --
%>% collect()

哪个返回
Running job [/] 20s
Complete
Billed 400GB
Downloading 230,000,000 rows
Downloading data [=====--------] 28% ETA: 24h

但是过了一段时间
Error: Invalid Credentials [authError]

问题

如何增加0Auth token 过期之前的时间长度?

最佳答案

我也有同样的错误,并且我遇到了超时问题。

另一个可能的解决方案是导出到google data studio,然后通过csv下载它作为解决方法。

或对于大型数据集,最好通过将BigQuery结果提取到Google Cloud Storage中,然后从此处下载数据来完成,具体方法如下:
https://mran.microsoft.com/web/packages/bigQueryR/vignettes/bigQueryR.html

    ## Create the data extract from BigQuery to Cloud Storage
job_extract <- bqr_extract_data("your_project",
"your_dataset",
"bigResultTable",
"your_cloud_storage_bucket_name")

## poll the extract job to check its status
## its done when job$status$state == "DONE"
bqr_get_job("your_project", job_extract$jobReference$jobId)

## to download via a URL and not logging in via Google Cloud Storage interface:
## Use an email that is Google account enabled
## Requires scopes:
## https://www.googleapis.com/auth/devstorage.full_control
## https://www.googleapis.com/auth/cloud-platform
## set via options("bigQueryR.scopes") and reauthenticate if needed

download_url <- bqr_grant_extract_access(job_extract, "your@email.com")

## download_url may be multiple if the data is > 1GB
> [1] "https://storage.cloud.google.com/big-query-r-extracts/extract-20160311112410-000000000000.csv"
> [2] "https://storage.cloud.google.com/big-query-r-extracts/extract-20160311112410-000000000001.csv"
> [3] "https://storage.cloud.google.com/big-query-r-extracts/extract-20160311112410-000000000002.csv"

关于r - 使用bigquery时,tidyverse API OAuth token 到期之前增加时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61676664/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com