【问题标题】:Google Drive: getting content of (an existing) file results in 404 response errorGoogle Drive:获取(现有)文件的内容会导致 404 响应错误
【发布时间】:2012-09-29 08:50:20
【问题描述】:

我的驱动器中有一个具有“公共”可见性的文件。我使用驱动器 api 的示例页面中的代码(如下)来检索文件内容。文件元数据显示我的文件在那里。但是 hhtp 响应告诉我它不存在(远程服务器返回错误:(404)未找到。)。(顺便说一下,文件是由具有“所有者”权限的用户上传的,现在我正在尝试检索具有“作者”权限的不同用户的同一个文件。)有什么想法吗?

    public static System.IO.Stream DownloadFile(
     IAuthenticator authenticator, Google.Apis.Drive.v2.Data.File file)
    {
        if (!String.IsNullOrEmpty(file.DownloadUrl))
        {
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(file.DownloadUrl));
                authenticator.ApplyAuthenticationToRequest(request);
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    return response.GetResponseStream();
                }
                else
                {
                    Console.WriteLine(
                        "An error occurred: " + response.StatusDescription);
                    return null;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("An error occurred: " + e.Message);
                return null;
            }
        }
        else
        {
            // The file doesn't have any content stored on Drive.
            return null;
        }
    }

【问题讨论】:

标签: c# asp.net httpresponse google-drive-api


【解决方案1】:

对于此类问题,请使用https://developers.google.com/drive/v2/reference/files/get#try-it的表单尝试

这样您就可以确定是您的代码有问题还是文件有问题。

【讨论】:

    猜你喜欢
    • 2012-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多