【问题标题】:Fields Parameter in Google Drive API V3Google Drive API V3 中的字段参数
【发布时间】:2016-09-29 17:18:35
【问题描述】:

我正在尝试通过 Google Drive API v3 检索用户信息。

var request = this.driveService.About.Get();
request.Fields = "user.displayName";

var accountInfo = await request.ExecuteAsync();

即使我指定了它在消息中抱怨的字段:

Google.Apis.Requests.RequestError 此方法需要 'fields' 参数。 [400]

“字段”是否还有其他含义?

【问题讨论】:

    标签: .net google-drive-api


    【解决方案1】:
    GoogleCredential credential = new GoogleCredential().setAccessToken(googleDriveAccessToken);
        credential.refreshToken();
    
    apachetransport = GoogleApacheHttpTransport.newTrustedTransport(); 
    
    Drive service = new  Drive.Builder(apachetransport, JSON_FACTORY,credential)
                    .setApplicationName(APPLICATION_NAME)
                    .build();
    
    Get get = service.about().get();
    
    com.google.api.services.drive.model.About about = get.setFields("user").execute();
    
    User user = about.getUser();
    
    System.out.println(user.getEmailAddress()); 
    

    【讨论】:

      【解决方案2】:

      我不知道它是否仍然有效,但这在过去对我有效:

              'https://www.googleapis.com/drive/v3/about?fields=user',
              {
                  method: 'GET',
                  headers: {
                      Authorization: 'Bearer ' + token,
                  }
              },
      

      【讨论】:

        【解决方案3】:

        我不得不使用 Oauth2Service 而不是 DriveService,像这样:

        var request = this.authService.Userinfo.Get();
        
        request.Fields = "email";
        
        var accountInfo = await request.ExecuteAsync();
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2016-12-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-04-10
          • 1970-01-01
          • 1970-01-01
          • 2020-09-18
          相关资源
          最近更新 更多