azure - Azure Function 中的本地文件

标签 azure azure-functions azure-function-app

我正在尝试使用azure函数(时间触发)访问谷歌驱动器,当授予访问驱动器的权限时,它会在运行时创建一个 token 文件。它在本地存储该文件,并且 azure 函数在本地运行良好。

但是部署时我收到一个错误,其中我收到的错误中描述了我的本地系统路径。当我部署该功能后,为什么它会存储我的本地系统路径? 它应该访问存储 Azure 函数的路径。

代码

        public DriveService GetService()
        {
            //get Credentials from client_secret.json file 
            UserCredential credential;
            string clientSecretString = config[Constant.ClientSecret];
            log.LogInformation("String value is " + clientSecretString);
            byte[] clientSecret = Encoding.UTF8.GetBytes(clientSecretString);
            using (var stream = new MemoryStream(clientSecret)) <----------------- Error Message 
            {

                log.LogInformation("Current path is " + Environment.CurrentDirectory);
                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(Environment.CurrentDirectory, false)).Result;
            }

            log.LogInformation("Completed ");
            //create Drive API service.
            DriveService service = new DriveService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = Constant.ApplicationName,
            });
            return service;
        }

错误消息: [错误] 在 System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) 在 System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification) 在 System.Threading.Tasks.Task1.get_Result ()位于 C:\Users\username\Documents\Project\GoogleDriveService.cs 中的 ExportSheetsToExcelPowerBi.GoogleDriveService.GetService():line

最佳答案

对于 Azure 函数应用程序,无需从 Google Auth 生成的 token 文件中读取 secret 。正如您之前的回答之一 posts 。您可以将函数应用配置为在 Azure 上运行时使用 Google 登录进行身份验证。要实现此目的,您必须使用服务器端应用程序的 Google 登录生成客户端 ID 和客户端 key ,使用此连接您可以将获得的 token 存储在 token 存储中。请引用this将您的函数应用配置为使用 Google Login 的文档,请参阅 this有关 token 存储以及如何检索和刷新获得的 token 的文档。

关于azure - Azure Function 中的本地文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63883073/

相关文章:

azure - 将 Visual Studio Professional 订阅添加到 Azure 帐户

c# - 通过 API 在 Team Services 中创建工作项

azure - 自托管 Azure DevOps Pipeline Agent 失败并出现错误“ token 受众无效”

java - 如何在@BlobOutput中动态定义 'path'?

Azure 函数发布

Azure函数: Multiple functions with different authentication

php - Azure SDK for php blob 下载导致内存不足

c# - 在 Visual Studio c# 中子类 MultipartStreamProvider 失败?

azure - 端点 Webhook URL 上的事件网格订阅 ARM 部署失败

python - 使用 Python 在 Azure 存储 blob 中创建 PDF 文件的最佳方法是什么?