首页 > 解决方案 > Google Directory API user list request failing with 400 Invalid Input

问题描述

I'm trying to get a successful response when executing the request from https://developers.google.com/admin-sdk/directory/v1/reference/users/list?apix_params=%7B%22customer%22%3A%22my_customer%22%7D. I'm getting a 400 Invalid Input response.

With the client library(https://www.npmjs.com/package/googleapis, v47), when calling:

google.admin('directory_v1')
  .users.list({
     auth: oAuth2Client,
     customer: 'my_customer',
     orderBy: 'email',
     maxResults: 500,
     pageToken: null
  }).then(...);

, I'm receiving a Request object in the success handler, instead of a valid response(response which should have had the shape described at the bottom of https://developers.google.com/admin-sdk/directory/v1/reference/users/list).

What am I doing wrong?

标签: google-apis-explorergoogle-directory-api

解决方案


原来问题出在身份验证过程中,使用google-auth-library. 我已经采取了这样的措施:

const {google} = require('googleapis');

const oAuthClient = await google.auth.getClient({keyFile: ..., scopes: [...]});
oAuthClient.credentials = await new google.auth.JWT(...).authorizeAsync();

const {data} = await google
  .admin({version: 'directory_v1', auth: oAuthClient})
  .users
  .list({
     customer: 'my_customer'
  });

推荐阅读