1

我正在尝试通过 google api 使用 curl 终端调用将新用户添加到我的 google 应用程序帐户域 ( link1 link2 )。

我已经有一个访问和刷新令牌,只需要弄清楚如何进行 api 调用。这是我一直在测试的:

//version 1
curl https://www.googleapis.com/admin/directory/v1/users \
-H "Authorization: Bearer {access_token_here}" \
-d '{"name":{"familyName":"pan","givenName":"peter"},"password":"asdf","primaryEmail":"asdf@dsf.com"}' \
-X POST

//version 2
curl https://www.googleapis.com/admin/directory/v1/users?fields=name%2Cpassword%2CprimaryEmail&key={api_key_for_browsers}
-H "Authorization: Bearer {access_token_here}" \
-d '{"name":{"familyName":"pan","givenName":"peter"},"password":"asdf","primaryEmail":"asdf@dsf.com"}' \
-X POST

但他们只是返回错误:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Login Required",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Login Required"
 }
}

即使我拥有的访问密钥来自用户登录并授予对我的应用程序的访问权限后提供的授权码。

我的问题:

  1. 即使我已经让用户登录,为什么我会收到“需要登录”错误?
  2. 格式化此查询的正确方法是什么?
4

0 回答 0