【发布时间】:2020-01-22 13:58:53
【问题描述】:
我正在开发一个 .net 核心项目,试图连接到谷歌表格。 在我的本地主机上运行时,一切顺利,通过 azure 发布应用程序时,我无法连接收到此错误:
加载资源失败:服务器响应状态为 502 (Bad Gateway)
这是我的代码:
UserCredential credential;
using (var stream =
new FileStream("client_id_1.json", FileMode.Open, FileAccess.Read))
{
string credPath = "token.json";
credPath = Path.Combine(credPath, ".credentials/sheets.googleapis.com-dotnet-quickstart.json");
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
}
Service = new SheetsService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
文件“client_id_1.json”包含以下内容:
{
"web": {
"client_id": "...",
"project_id": "...",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_secret": "...",
"redirect_uris": [ "https://{{mySiteHomePage}}" ],
"javascript_origins": [ "https://{{mySite}}" ]
}
}
我有什么遗漏吗?我该如何解决这个问题?
【问题讨论】:
标签: c# azure google-oauth google-sheets-api google-api-dotnet-client