我试图通过Google Drive API v3检索用户信息。
var request = this.driveService.About.Get();
request.Fields = "user.displayName";
var accountInfo = await request.ExecuteAsync();
即使我用消息指定了它抱怨的字段:
Google.Apis.Requests.RequestError '字段'此方法需要参数。 [400]
'字段'
是否意味着其他内容答案 0 :(得分:2)
我必须使用Oauth2Service而不是DriveService,如下所示:
var request = this.authService.Userinfo.Get();
request.Fields = "email";
var accountInfo = await request.ExecuteAsync();
答案 1 :(得分:1)
我不知道它是否仍然有效,但这在过去对我有用:
'https://www.googleapis.com/drive/v3/about?fields=user',
{
method: 'GET',
headers: {
Authorization: 'Bearer ' + token,
}
},
答案 2 :(得分:0)
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());