我想创建一个闪亮的应用程序,它使用bigrquery连接到BigQuery API并运行一个查询。我使用以下代码执行查询:
library(bigrquery)
project <- "PROJECT_ID" # put your project ID here
sql <- 'QUERY '
test <- query_exec(sql, project = project)但在此之前,bigrquery包中有一个身份验证过程,如下所示:
google <- oauth_endpoint(NULL, "auth", "token",
base_url = "https://accounts.google.com/o/oauth2")
bigqr <- oauth_app("google",
"465736758727.apps.googleusercontent.com",
"fJbIIyoIag0oA6p114lwsV2r")
cred <- oauth2.0_token(google, bigqr,
scope = c(
"https://www.googleapis.com/auth/bigquery",
"https://www.googleapis.com/auth/cloud-platform"))如何在我的应用程序中集成
问候
发布于 2016-07-11 07:22:52
我有一个建议,类似于我在关于服务器端访问Google分析数据的问题上提供的答案,那就是使用Google服务帐户。通过CRAN提供的googleAuthR包由马克·埃德蒙森提供,它提供了使用Google帐户在R中执行服务器端身份验证的功能。同一个作者的另一个包名为bigQueryR (也在CRAN上),它与googleAuthR集成,并使用得到的身份验证令牌执行对Google的查询。
为实现这一目标:
googleAuthR进行身份验证时,提供私有密钥JSON文件的位置作为参数(参见下面的示例):下面的示例R脚本基于bigrquery包中的一个示例,引用包含私钥的JSON文件,并执行基本的BigQuery查询。请记住将json_file参数设置为适当的文件路径,并将project参数设置为Google BigQuery项目:
library(googleAuthR)
library(bigQueryR)
gar_auth_service(
json_file = "API Project-xxxxxxxxxxxx.json",
scope = "https://www.googleapis.com/auth/bigquery"
)
project <- "project_id" # put your project ID here
sql <- "SELECT year, month, day, weight_pounds
FROM [publicdata:samples.natality] LIMIT 5"
bqr_query(projectId = project, query = sql, datasetId = "samples")https://stackoverflow.com/questions/26263003
复制相似问题