GotoWebinar REST API - 自定义问题

时间:2012-06-05 15:17:17

标签: php json api

请保存我的堆栈溢出..并且我正在祷告有人使用API​​注册了参与者(并提交了自定义问题的答案)。

好的,首先,这是创建注册人的文档:

POST https://api.citrixonline.com/G2W/rest/organizers/73563532324/webinars/89... HTTP/1.1
Accept: application/json
Accept: application/vnd.citrix.g2wapi-v1.1+json
Content-Type: application/json
Authorization: OAuth oauth_token={oauthToken}

{
  "firstName":"Saumil",
  "lastName":"Jhaveri",
  "email":"test@test.com",
  "address":"650+Townsend+St,+St.+325",
  "city":"San+Francisco",
  "state":"California",
  "zipCode":"94103",
  "country":"United+States",
  "phone":"3123751884",
  "industry":"Accounting",
  "organization":"Citrix",
  "jobTitle":"Software+Engineer",
  "purchasingTimeFrame":"13+months",
  "roleInPurchaseProcess":"Decision+Maker",
  "numberOfEmployees":"120",
  "questionsAndComments":"No+Comments!",
  "responses":[
    {
      "questionKey":152,
      "responseText":"Fantastic!"
    }, {
      "questionKey":151,
      "answerKey":152
    }
  ]
}

因此,正如您从上面的json rest示例中所看到的,REST主体需要是“普通”值的数组,例如名称,电子邮件等......

如果你看看示例的底部附近,你会在这个数组中看到一个叫做响应的数组。

此数组包含自定义问题ID和用户响应的数组。

那么只有一个自定义问题会发生什么?

我试过了:

array('firstName' => $fname, 'lastName' => $lname, 'email' => $em, 
'responses' => array('questionKey' => 300000000000042400, 'responseText' => $custom));

并尝试过(即使只有一个问题,也是一个数组数组):

array('firstName' => $fname, 'lastName' => $lname, 'email' => $em, 
'responses' => array(array('questionKey' => 300000000000042400, 'responseText' => $custom)));

如果我在我的数据上运行json_encode,那么这就是输出

{
   "firstName":"Ellis",
   "lastName":"Ryan",
   "email":"ryanthecloser@gmail.com",
   "responses":[
      {
         "questionKey":3.0e+17,
         "responseText":"http:\/\/facebook.com\/doubleyourlikes"
      }
   ]
}

当我输入这个问题时,我想我看到了这个问题...我的json数据(更具体地说是问题密钥)正在被转换为科学记数法...我尝试将questionKey作为字符串提交,但这不起作用。

我希望科学记谱法是问题所在。任何人有任何想法如何在PHP这个大的数字: 300000000000042400

能够在没有转换数字的情况下编码_json吗?或者,如果有人成功获得使用api为注册人显示的自定义问题回复,请告诉我们!

提前致谢!

2 个答案:

答案 0 :(得分:4)

叹息

将问题密钥作为字符串传递是100%罚款,因此问题就消失了......

我的问题实际上是创建注册人的两个版本:

第一版:接受姓名和电子邮件,并丢弃其他所有内容 第二版:添加
接受:application / vnd.citrix.g2wapi-v1.1 + json

到标题以选择第二个版本。第二个版本允许自定义字段。

因为我没有包含额外的标题参数,所以我的自定义字段数据被丢弃了!

Grrrr我在文档中读了很多次...... RTM!并且做了它说的内容lol!

答案 1 :(得分:0)

为了使LARGE整数保持为数字,您必须将PHP更新为版本5.4+并使用类似

的内容
$response = curl_exec( $ch );

$json = json_decode( $response, true, 512, JSON_BIGINT_AS_STRING );

$response = curl_exec( $ch );

$response = preg_replace('/("\w+"):(\d+)/', '\\1:"\\2"', $response );  # quote the number
$json = json_decode( $response );