2012-07-02 24 views
1

我使用下面的代碼以註冊用戶的網絡研討會:如何通過PHP調用CITRIX API註冊新的GotoWebinar與會者?

$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:[email protected]', 
    ); 

$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":"[email protected]", 
     "status":"WAITING", 
     "registrationDate":"2012-06-29T21:07:10Z", 
     "joinUrl":"https://www1.gotomeeting.com/join/141654337/106660361", 
     "timeZone":"America/Denver" 
    } 
] 

我使用的創建研討會URL,那麼爲什麼我收到的信息的用戶是否已經註冊?

回答

0

的問題是,3歲,但考慮到CITRIX 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; 

獲取網絡研討會...

$webinarID = preg_replace("/[^0-9]/", "", $_POST[ "WebinarKey" ]); 

設置的URL CITRIX API(不需要resendConfirmation選項)...

$gtw_url = "https://api.citrixonline.com/G2W/rest/organizers/" . $organizer_key . "/webinars/" . $webinarID . "/registrants?resendConfirmation=false"; 

格式的POST頭...

$headers = array(
     "HTTP/1.1", 
     "Accept: application/json", 
     "Content-Type: application/json", 
     "Authorization: OAuth oauth_token=$access_token", 
     "Content-Length: " . strlen($newRegistrantFields) 
    ); 

設置我們的CURL選項,確保我們指定一個POST,CURLOPT_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>'; 

如果的errorCode鍵返回,然後登記炸燬。所有我在這裏做的是抓住從服務器的實際錯誤的描述,並加載它回到我打電話HTML頁面,但是這完全是可選...

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; 
    } 
0
<?php 
if (isset($_POST['registration-submission'])) { 
$base_url = 'https://api.citrixonline.com/G2W/rest'; 
$org_key = $_POST['organizer_key']; 
$web_key = $_POST['webinar_key']; 
$access_token = 'xxxxx'; 

$gtwPost = (object) array(
'firstName' => $POST['fname'], 
'lastName' => $POST['lname'], 
'email'=> $POST['email'], 
); 
$newRegistrantFields = json_encode($gtwPost); 
$headers = array(
     'HTTP/1.1', 
     'Accept: application/vnd.citrix.g2wapi-v1.1+json', 
     'Content-Type: application/json', 
     'Authorization: OAuth oauth_token=xxxxx', 
     'Content-Length:' . strlen($newRegistrantFields) 
     ); 


//Set POST URL for GoToWebinar 
$gtw_url = $base_url.'/organizers/'.$org_key.'/webinars/'.$web_key.'/registrants?resendConfirmation=false'; 

//Start GoToWebinar submission 

$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); 
$newRegistrantsArray = json_decode($newRegistrants,true); 


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; 
} 
} 
?> 

the code is not working. Please help me with this.