通过Azure功能访问Google云端硬盘 [英] Accessing Google Drive through Azure Function

查看:72
本文介绍了通过Azure功能访问Google云端硬盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任务是下载Excel格式的Google表格,并使用Azure时间触发功能及时将其存储在Azure Blob存储中.

The task is to download google sheet in excel format and store it in Azure blob storage on timely basics using the Azure time trigger function.

对用户Google驱动器的访问方法-OAuth客户端ID.

Access Method to users google drive - OAuth Client ID.

我已经在本地创建了一个Azure函数,它可以按预期正常工作并执行任务,但是当我部署Azure函数时会出现此错误.

I have created an Azure function locally and it works fine as expected and performs the task but when I deploy azure function I get this error.

DriveService的代码,其中根据部署时的堆栈跟踪发生错误

Code for DriveService where the error occurs according to stack trace when deployed

public string[] Scopes = { DriveService.Scope.Drive, DriveService.Scope.DriveReadonly };
public DriveService GetService()
        {
              UserCredential _credential;
 //Error Occurs at line below
            Google.Apis.Auth.OAuth2.Flows.GoogleAuthorizationCodeFlow googleAuthFlow = new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer()
            {
                ClientSecrets = new ClientSecrets
                {
                    ClientId = _config[Constant.ClientId],
                    ClientSecret = _config[Constant.ClientSecret],
                }
            });

            string FilePath = Path.GetDirectoryName(_driveCredentialsPath);

            _credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                googleAuthFlow.ClientSecrets,
                Scopes,
                "user",
                CancellationToken.None,
                new FileDataStore(FilePath, true)).Result;

            DriveService service = new DriveService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = _credential,
                ApplicationName = Constant.ApplicationName,
            });
            return service;
        }

我认为在两种情况下它可能会出错,但是我不确定.

I think there are two situations where it can go wrong but I am not sure about it.

  1. 当我在本地运行该应用程序时,会出现一个同意屏幕,并授予访问驱动器的权限.当同一功能在Azure上运行时,谁以及如何授予访问驱动器的权限.

我已如下所述在Google OAuth同意屏幕上提供了我的Azure应用URL,以解决这种情况.

I have provided my Azure App URL on Google OAuth Consent Screen as mentioned below to overcome this situation.

  1. 在授予访问驱动器权限后在本地运行时,它会创建一个TOKENRESPONSE-USER文件,该文件由访问令牌,到期刷新令牌和范围组成.

是否有可能在部署功能时无法在azure功能上创建TOKENRESPONSE-USER文件?

Is this possible that when the function is deployed it is unable to create a TOKENRESPONSE-USER file on azure function?

请让我知道为什么会出现此错误,或者我需要在过程中进行一些更改.

Please let me know why I am getting this error or do I need to change something in my process.

推荐答案

您可以将功能应用程序配置为在Azure上运行时使用Google登录进行身份验证.为此,您必须使用Google登录服务器端应用程序生成客户端ID和客户端密钥,使用此连接,您可以将获得的令牌存储在令牌存储中.请参阅文档以配置您的功能应用程序以使用Google登录,请参考

You can configure your function app to use Google login for authentication purposes when running on Azure. To achieve this you have to generate client id and client secret using the Google sign-in for server-side apps, using this connection you can store the tokens obtained in the token store. Please refer to this document to configure your function app to use Google Login, refer to this document regarding the token store and how to retrieve and refresh the token obtained.

这篇关于通过Azure功能访问Google云端硬盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆