【发布时间】:2017-12-01 08:51:20
【问题描述】:
我正在开发一个应用程序,它需要使用用户 ID 访问“简单数据库”(谷歌电子表格)。
我尝试使用 Oauth2.0 但这不是我需要的。
我正在使用此代码来访问工作表:
private static SheetsService AuthorizeGoogleApp()
{
UserCredential credential;
using (var stream =
new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
{
string credPath = System.Environment.GetFolderPath(
System.Environment.SpecialFolder.Personal);
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;
Console.WriteLine("Credential file saved to: " + credPath);
}
// Create Google Sheets API service.
var service = new SheetsService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
return service;
}
但使用此代码,C# 应用程序会打开浏览器,要求用户登录其 google 帐户。
我需要通过 API 访问,因此它对用户是透明的。 我已经有了 api 密钥,但我不知道如何使用,也没有在 Google 网站上找到任何文档。
你能帮我举个例子来阅读一个简单的专栏吗?
提前致谢!
【问题讨论】: