C#Google云端硬盘列表文件

时间:2013-11-07 13:42:24

标签: c# google-drive-api

我正在尝试将Windows服务应用与Google云端硬盘集成。交互式身份验证在此方案中不起作用。我一直在查看网络上的所有文档,但仍然无法使其工作。

当我使用.net客户端API调用服务时,应用程序只会挂起List请求的Execute()命令。

如果我看小提琴手,我会看到:
HTTP/1.1 200 OK
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Date: Thu, 07 Nov 2013 13:31:08 GMT
Content-Type: application/json
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Alternate-Protocol: 443:quic
Transfer-Encoding: chunked
7f
{
"access_token" : "ya29.AHES6ZRUlkSmg43b4jTY6xkakf0WL3O-blnmp5D3sNoaMYY",
"token_type" : "Bearer",
"expires_in" : 3600
}
0

但没有别的。

如果我仅使用http请求调用该服务,则会收到401 Login Required响应。 如果我看小提琴手,我看到的只是401的回应而不是请求。

身份验证代码为:

 var certificate = new X509Certificate2(sKeyPath, "notasecret", X509KeyStorageFlags.Exportable);

        ServiceAccountCredential credential = new ServiceAccountCredential(
            new ServiceAccountCredential.Initializer(sEmail)
           {
               Scopes = new[] { DriveService.Scope.Drive, DriveService.Scope.DriveAppdata, DriveService.Scope.DriveScripts }

           }.FromCertificate(certificate));


        // Create the service.
        service = new DriveService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = "servauth"
        });

文件列表的代码在这里:

     //Using Google API
        FilesResource.ListRequest requestApi = service.Files.List();
        //Stops on this line
        var listFiles = requestApi.Execute();

        //Using webrequest
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.googleapis.com/drive/v2/files");
        request.Method = "GET";
        service.Authenticator.ApplyAuthenticationToRequest(request);

        //Response here is 401
        WebResponse webResponse = request.GetResponse();

0 个答案:

没有答案