小编Ana*_*eam的帖子

使用 google flow 2.0 时无法将用户重定向到 auth_uri

我正在开发一个使用 YouTube 分析 API 提取 YouTube 指标的应用程序。这是我第一次使用 google auth flow 来验证我的应用程序,以便它可以默默地提取报告。

我按照下面的谷歌发布的文章来解决同样的问题: https ://developers.google.com/youtube/reporting/guides/authorization/server-side-web-apps

在阅读本文时,我无法弄清楚如何将用户重定向到 auth_uri 并获取 auth_code。

下面是我迄今为止为身份验证流程编写的代码:

API_SERVICE_NAME = 'youtubeAnalytics'
API_VERSION = 'v2'
CLIENT_SECRETS_FILE = 'C:/Users/Tushar/Documents/Serato_Video_Intelligence/client_secret_youtube.json'
def get_service():
  global auth_code
  global auth_uri
  flow = client.flow_from_clientsecrets(
  CLIENT_SECRETS_FILE, 
  scope='https://www.googleapis.com/auth/yt-analytics.readonly',
  redirect_uri = "http://localhost:8080")
  flow.params['access_type'] = 'offline'
  flow.params['include_granted_scopes'] = True
  auth_uri = flow.step1_get_authorize_url()
  credentials = flow.step2_exchange(auth_code)
  http_auth = credentials.authorize(httplib2.Http())
  return build(API_SERVICE_NAME, API_VERSION, http=http_auth)
  
def execute_api_request(client_library_function, **kwargs):
  response = client_library_function(
    **kwargs
  ).execute()
        

if __name__ == '__main__':
  # Disable OAuthlib's HTTPs verification when running …
Run Code Online (Sandbox Code Playgroud)

google-api oauth-2.0 python-3.x youtube-analytics-api

3
推荐指数
1
解决办法
1460
查看次数

错误:(gcloud.app.deploy)使用自定义运行时时必须提供自己的 Dockerfile

我正在尝试使用 App Engine 在 Google Cloud 上安排 R 作业。我正在关注这篇文章

https://code.markedmondson.me/4-ways-schedule-r-scripts-on-google-cloud-platform/

但是,当我尝试使用部署应用程序时,gcloud app deploy --project shiny-demo出现以下错误

Enabling service [appengineflex.googleapis.com] on project [shiny-demo]...
Waiting for async operation operations/acf.33c5e6da-6f9e-4e66-b7d3-f0611eddc0ce to complete...
Operation finished successfully. The following command can describe the Operation details:
 gcloud services operations describe operations/tmo-acf.33c5e6da-6f9e-4e66-b7d3-f0611eddc0ce
Beginning deployment of service [default]...
ERROR: (gcloud.app.deploy) You must provide your own Dockerfile when using a custom runtime. Otherwise provide a "runtime" field with one of the supported runtimes.
Run Code Online (Sandbox Code Playgroud)

我的 yaml 文件在同一文件夹中确实有一个 Dockerfile,但不知何故它无法识别该 Dockerfile。下面是我的 …

google-app-engine yaml r docker google-cloud-platform

3
推荐指数
1
解决办法
1026
查看次数

如何在 Docker 中安装 R Github 包

我正在尝试为 R 脚本创建 Docker 映像,以在 Google Cloud 上安排 R 作业。我目前正在使用一个小型 R 脚本对其进行测试。命令docker build在我安装的步骤失败rga。下面是我的 R 脚本和 DockerFile:

\n\n

R脚本:

\n\n
library(rga)\nlibrary(bigrquery)\nbq_token()\nrga.open(instance = "ga", where="~/ga.rga")\n\ndemoScheduleAPI <- function(){\n  search_perf <- ga$getData(XXXX, batch = TRUE, walk = TRUE, \n                          start.date = "2020-01-15",\n                          end.date = "2020-01-16",\n                          metrics = "ga:searchUniques",\n                          dimensions="ga:date,ga:hour,ga:searchKeyword, ga:searchCategory ,ga:dimension6,ga:dimension10")\n  project <- "bidone-data"\n  insert_upload_job(project, "GA_Export_Prod_DataSet", "Test_Table123", search_perf)\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

Dockerfile

\n\n
FROM rocker/r-ver:3.6.1\n\nRUN mkdir /home/bidone\n\nRUN R -e "install.packages(\'bigrquery\', repos=\'http://cran.rstudio.com/\')"\n\nRUN R -e "install.packages(\'devtools\', repos=\'http://cloud.r-project.org\')"\n\nRUN R -e "devtools::install_github(\'skardhamar/rga\')"\n\nCOPY .secrets /home/analysis/.secrets\n\nCOPY ga /home/analysis/ga\n\nCOPY …
Run Code Online (Sandbox Code Playgroud)

google-analytics r github devtools docker

3
推荐指数
1
解决办法
2625
查看次数

R没有提供正确的星期数

您好,我正在寻找三年内一系列日期的星期数。但是,R没有提供正确的星期数。我正在生成从2016-04-01到2019-03-30的日期序列,然后尝试计算三年的周数,这样我就得到了第54、55、56周。

但是,当我检查2016-04-03的星期时,R将星期数显示为14,与excel交叉检查时,它是星期数15,并且它只是计算7天而未引用实际的日历天。另外,每年的第一个星期从1开始

代码看起来像这样

days <- seq(as.Date("2016-04-03"),as.Date("2019-03-30"),'days')
weekdays <- data.frame('days'=days, Month = month(days), week = week(days),nweek = rep(1,length(days)))
Run Code Online (Sandbox Code Playgroud)

结果是这样的

   days    week
2016-04-01  14
2016-04-02  14
2016-04-03  14
2016-04-04  14
2016-04-05  14
2016-04-06  14
2016-04-07  14
2016-04-08  15
2016-04-09  15
2016-04-10  15
2016-04-11  15
2016-04-12  15
Run Code Online (Sandbox Code Playgroud)

但是当从excel检查时,这就是我得到的

   days    week
2016-04-01  14
2016-04-02  14
2016-04-03  15
2016-04-04  15
2016-04-05  15
2016-04-06  15
2016-04-07  15
2016-04-08  15
2016-04-09  15
2016-04-10  16
2016-04-11  16
2016-04-12  16
Run Code Online (Sandbox Code Playgroud)

有人可以帮助我确定我哪里出错了。

在此先多谢!!

datetime r week-number

0
推荐指数
1
解决办法
104
查看次数

合并熊猫中的列以创建新列

您好,我正在研究pandas数据框,我想创建一个包含多个列并对其应用条件的列,我正在寻找一种做到这一点的聪明方法。

假设数据框看起来像

A   B   C   D
1   0   0   0
0   1   0   0
0   0   1   0
1   0   1   0
1   1   1   0
0   0   1   1
Run Code Online (Sandbox Code Playgroud)

我的输出列应如下

A   B   C   D   Output_col
1   0   0   0   A
0   1   0   0   B
0   0   1   0   C
1   0   1   0   A_C
1   1   1   0   A_B_C
0   0   1   1   C_D
Run Code Online (Sandbox Code Playgroud)

我当然可以使用下面的代码来实现这一点,但是我必须对每一列都做到这一点。

test['Output_col'] = test.A.apply(lambda x: A if x > 0 else 0)
Run Code Online (Sandbox Code Playgroud)

我想知道是否有一种方法可以在我有很多列的情况下不应用每一列而实现这一目标。

提前致谢 …

dataframe python-3.x pandas feature-engineering

0
推荐指数
1
解决办法
59
查看次数

如何在 R 中打印实际的错误消息

我试图返回 R 函数中的任何实际错误消息,并向其发送电子邮件以通知用户,但它仅打印 R 参数中的自定义消息。有什么办法可以在电子邮件中发送实际的错误消息吗?

以下是我迄今为止编写的虚拟脚本:

mailme <- function(message){
  #function to send email
}

b<-function(){
  r <- NULL
  attempt <- 1
  while( is.null(r) && attempt <= 3 ) {
    attempt <- attempt + 1
    try({
      x<-2+3
      prin(x)})
  }
  stop("The error message")
}

a <- tryCatch({
  b()
}, error = function(e){
  mailme(e$message)
})
  
Run Code Online (Sandbox Code Playgroud)

实际返回的错误信息是

Error in prin(x) : could not find function "prin"
Run Code Online (Sandbox Code Playgroud)

但是我在电子邮件中收到的错误消息是

The error message  #from the stop used in function b
Run Code Online (Sandbox Code Playgroud)

如何在停靠点内调用实际的错误消息?

error-handling r try-catch

0
推荐指数
1
解决办法
1525
查看次数