1

我正在尝试将 Windows 服务应用程序与 Google Drive 集成。在这种情况下,交互式身份验证将不起作用。我一直在浏览网络上的所有文档,但仍然无法使其正常工作。

当我使用 .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();
4

0 回答 0