Google g 套件无效 Given/Family 姓名:FamilyName (ColdFusion/HTTP POST)

Google g suite Invalid Given/Family Name: FamilyName (ColdFusion/HTTP POST)

我看过几篇关于这个问题的帖子,但我无法使用这些建议来克服我的问题。以下是我的代码和结果:

<cffunction name="CreateUser" hint="Create new GSuite user." returntype="struct" access="public">
     <cfargument name="token" hint="The Google-provided access token." type="string" required="yes">
     <cfargument name="state" hint="The unique anti-forgery string." type="string" required="yes">
     <cfargument name="userdata" hint="A json string containing user data" type="string" required="yes">
     <cfargument name="api" hint="API Key for the Google Domain" type="string" required="yes">

     <cfhttp method="post" charset="utf-8" url="https://www.googleapis.com/admin/directory/v1/users?state=#state#&access_token=#token#" result="uResult">
          <cfhttpparam type="header" name="auth" value="Authorization: Bearer #token#">
          <cfhttpparam type="header" name="accept" value="Accept: application/json">
          <cfhttpparam type="header" name="content" value="Content-type: application/json">
          <cfhttpparam type="body" name="body" value=#userdata#>
     </cfhttp>

     <cfreturn uResult>
</cffunction>

正在使用的 JSON 字符串是:

{
  "password":"Test@me12!",
  "primaryEmail":"John@doe.com",
  "name":
    {
     "familyName":"Doe",
     "givenName":"John"
    }
}

我正在使用以下示例中的 HTTP POST 结构: Google Users: insert (Directory API)

我从 Google 得到的结果是这样的:

{
  "error": {
    "errors": [
      {
       "domain": "global",
       "reason": "invalid",
       "message": "Invalid Given/Family Name: FamilyName"
      }
   ],
   "code": 400,
   "message": "Invalid Given/Family Name: FamilyName"
  }
}

我不明白哪里出了问题。根据其他帖子,我已经包含了 content-type。根据 Google 的示例,我包含了接受 header 和授权 header。尽管如此,我还是无法得到不同的结果。

如果我将 JSON 字符串传递给函数并在上面的 Google link 中使用它,我就可以创建用户。但是,如果我通过 HTTP POST 传递它,我就不能。请告诉我那里某处有一个杂散的逗号或缺少一个点。

你的header"name"和"values"看起来不对。不要将 header names 放在 "value" 属性中。这就是 "name" 属性的用途:-)

例如授权和处置headers应该是:

 <cfhttpparam type="header" name="Content-Type" value="application/json"> 
 <cfhttpparam type="header" name="Authorization" value="Bearer #token#">

此外,"body"参数没有"name"属性,只有一个"value":

<cfhttpparam type="body" value="#userdata#"> 

有关详细信息,另请参阅 cfhttpparam documentation