【问题标题】:Google Spreadsheets Api Key exampleGoogle 电子表格 API 密钥示例
【发布时间】: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 网站上找到任何文档。

你能帮我举个例子来阅读一个简单的专栏吗?

提前致谢!

【问题讨论】:

    标签: c# google-spreadsheet-api


    【解决方案1】:

    Here 是 API 的文档。 它还包括授权。

    【讨论】:

    • 您好 Maurice,我在文档中找不到使用 api 密钥的工作示例。可以发在这里吗?
    • 我的错,我链接了旧的 API。您可以在此处找到 API 密钥的说明:developers.google.com/sheets/api/guides/…
    • 获得 API 密钥后,您的应用程序可以将查询参数 key=yourAPIKey 附加到所有请求 URL。
    • 我不明白如何提出请求,我总是得到 403 Unauthorized
    猜你喜欢
    • 1970-01-01
    • 2015-09-11
    • 2017-04-07
    • 1970-01-01
    • 1970-01-01
    • 2019-04-18
    • 1970-01-01
    • 2015-01-04
    • 2018-04-25
    相关资源
    最近更新 更多