【问题标题】:Google Drive API bad request from C# but fine from Postman来自 C# 的 Google Drive API 错误请求,但来自 Postman 的请求很好
【发布时间】:2019-08-28 17:53:34
【问题描述】:

我正在使用来自 C# 的此请求代码并获得错误的请求结果:

    public class GoogleDriveManager
    {
        private static readonly HttpClient Client = new HttpClient();
        private const string Access = "ACCESS";

        public GoogleDriveManager()
        {
            Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Access);
        }

        public async Task<HttpResponseMessage> GetFilesAsync(string driveId)
        {
            var url =
                $"https://www.googleapis.com/drive/v3/files?driveId={driveId}&includeItemsFromAllDrives=true&corpora=true&supportsAllDrives=true";
            var result = await Client.GetAsync(url);
            return result;
        }
   }

但是当我向 Postman 提出同样的请求时,效果很好:

获取https://www.googleapis.com/drive/v3/files?driveId=DRIVEID&includeItemsFromAllDrives=true&corpora=drive&supportsAllDrives=true

(Authorization Bearer Token,token值同上)

我在 C# 方面做错了什么?

【问题讨论】:

    标签: c# http google-api


    【解决方案1】:

    根据 API documentation,语料库支持的值为:

    • 用户
    • 开车
    • 所有驱动器

    您的 Postman 示例具有 corpora=drive,但您的 C# 示例显示 corpora=true。

    【讨论】:

    • 头撞桌子
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-16
    • 1970-01-01
    • 2020-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-25
    相关资源
    最近更新 更多