格式化Google API调用 - 创建/插入用户到域,错误:需要登录

时间:2013-07-25 18:07:31

标签: curl google-api

我正在尝试通过google api使用curl终端电话将新用户添加到我的Google Apps应用帐户域(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. 格式化此查询的正确方法是什么?

0 个答案:

没有答案