我如何通过PHP调用CITRIX(LogMeIn)API来注册新的GoTowBinar与会者?
我使用以下代码注册用户参加网络研讨会:我如何通过PHP调用CITRIX(LogMeIn)API来注册新的GoTowBinar与会者?,php,curl,citrix,logmein,Php,Curl,Citrix,Logmein,我使用以下代码注册用户参加网络研讨会: $headers = array( 'HTTP/1.1', 'Accept: application/json', 'Accept: application/vnd.citrix.g2wapi-v1.1+json', 'Content-Type: application/json', 'Authorization: OAuth oauth_token='.$access_token, 'Name_First:test', '
$headers = array(
'HTTP/1.1',
'Accept: application/json',
'Accept: application/vnd.citrix.g2wapi-v1.1+json',
'Content-Type: application/json',
'Authorization: OAuth oauth_token='.$access_token,
'Name_First:test',
'Name_Last:ank',
'Email:ankinfo@yahoo.com',
);
$gtw_url = "https://api.citrixonline.com/G2W/rest/organizers/{organizerkey}/webinars/{webinarkey}/registrants";
$curl = @curl_init();
@curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
@curl_setopt($curl, CURLOPT_URL, $gtw_url);
@curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
@curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
@curl_exec($curl);
@curl_close($curl);
我已通过网络研讨会密钥和组织者密钥。我应该得到如下输出:
HTTP/1.1 201 OK Content-Type: application/json
{
"registrantKey":5678,
"joinUrl":"https://www1.gotomeeting.com/join/123456789/5678"
}
问题是,当我运行该文件时,我得到了输出
[
{
"registrantKey":106660361,
"firstName":"test",
"lastName":"1",
"email":"rohankapoor99@yahoo.com",
"status":"WAITING",
"registrationDate":"2012-06-29T21:07:10Z",
"joinUrl":"https://www1.gotomeeting.com/join/141654337/106660361",
"timeZone":"America/Denver"
}
]
我使用的是create webinar URL,那么为什么我要获取已注册用户的信息呢?这个问题已经存在3年了,但考虑到CITRIX(现在是LogMeIn)API文档目前的糟糕状态,我提供以下代码片段作为可能的解决方案: 显然,我们的帐户需要组织者密钥和访问令牌数据
$organizer_key= '10000000000XXXXXXX';
$access_token = 'GwsiiPWaJbHIiaIiocxxxxxxxxxx';
获取网络研讨会所需的最小字段(例如,从HTML表单),并对数据进行JSON编码
$newRegFields = (object) array(
'firstName' => $_POST[ 'FirstName' ],
'lastName' => $_POST[ 'LastName' ],
'email' => $_POST[ 'Email' ],
);
$newRegistrantFields = json_encode( $newRegFields );
//echo '<br><br>' . $newRegistrantFields;
将URL设置为LogMeIn API(不需要resendConfirmation选项)
格式化我们的文章标题
$headers = array(
"HTTP/1.1",
"Accept: application/json",
"Content-Type: application/json",
"Authorization: OAuth oauth_token=$access_token",
"Content-Length: " . strlen( $newRegistrantFields )
);
设置卷曲选项,确保使用CURLOPT\u POST,1指定一篇文章
$curl = curl_init();
curl_setopt( $curl, CURLOPT_URL, $gtw_url );
curl_setopt( $curl, CURLOPT_HTTPHEADER, $headers );
curl_setopt( $curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0 );
curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $curl, CURLOPT_POST, 1 );
curl_setopt( $curl, CURLOPT_POSTFIELDS, $newRegistrantFields );
$newRegistrants = curl_exec( $curl );
curl_close( $curl );
我们的cURL调用返回了JSON编码的数据,无论是服务器错误消息还是注册确认。现在,让我们将回复转换为一个方便的关联数组
$newRegistrantsArray = json_decode( $newRegistrants, true );
//echo '<br><br>' . $newRegistrants . '<br><br>';
//echo '<pre>'; print_r( $newRegistrantsArray ); echo '</pre>';
现在,如果注册成功,服务器将返回如下内容
if( array_key_exists( 'registrantKey', $newRegistrantsArray ) && array_key_exists( 'joinUrl', $newRegistrantsArray ) ) {
$form_data[ 'status' ] = true;
$form_data[ 'code' ] = $_POST[ 'Email' ] . ' successfully registered with webinar';
$form_data[ 'error' ] = 'E300';
//echo json_encode( $form_data );
//exit;
}
…所以我只是想看看那些钥匙是否归还了,如果是的话,我知道注册情况良好
$newRegistrantsArray = json_decode( $newRegistrants, true );
//echo '<br><br>' . $newRegistrants . '<br><br>';
//echo '<pre>'; print_r( $newRegistrantsArray ); echo '</pre>';
if( array_key_exists( 'errorCode', $newRegistrantsArray )) {
$form_data[ 'status' ] = false;
$form_data[ 'code' ] = $newRegistrantsArray[ 'description' ];
$form_data[ 'error' ] = 'E200';
//echo json_encode( $form_data );
//exit;
}
(
[registrantKey] => 2.5022062212198E+18
[joinUrl] => https://global.gotowebinar.com/join/6552167171182613761/103193261
)
if( array_key_exists( 'registrantKey', $newRegistrantsArray ) && array_key_exists( 'joinUrl', $newRegistrantsArray ) ) {
$form_data[ 'status' ] = true;
$form_data[ 'code' ] = $_POST[ 'Email' ] . ' successfully registered with webinar';
$form_data[ 'error' ] = 'E300';
//echo json_encode( $form_data );
//exit;
}