【发布时间】:2020-09-16 10:51:15
【问题描述】:
任务是下载excel格式的google sheet,并使用Azure时间触发功能将其存储在Azure blob存储中。
用户 google drive 的访问方法 - OAuth Client ID。
我在本地创建了一个 Azure 函数,它按预期工作并执行任务,但是当我部署 azure 函数时出现此错误。
部署时根据堆栈跟踪发生错误的 DriveService 代码
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;
}
我认为有两种情况可能会出错,但我不确定。
我在 Google OAuth 同意屏幕上提供了我的 Azure 应用 URL,如下所述,以克服这种情况。
是否有可能在部署函数时无法在 azure 函数上创建 TOKENRESPONSE-USER 文件?
请让我知道为什么我会收到此错误,或者我是否需要更改我的流程中的某些内容。
【问题讨论】:
标签: azure google-drive-api azure-functions azure-function-app