如何通过PHP调用CITRIX(LogMeIn)API来注册新的GotoWebinar参与者? [英] How do I call CITRIX (LogMeIn) API via PHP to register new GotoWebinar attendee?

查看:104
本文介绍了如何通过PHP调用CITRIX(LogMeIn)API来注册新的GotoWebinar参与者?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码将用户注册到网络研讨会:

I am using the below code to register user to the webinar:

   $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);

我已经通过了网络研讨会密钥和组织者密钥。我应该得到这样的输出:

I have passed webinar key and organizer key. I am supposed to get the output like:

HTTP/1.1 201 OK Content-Type: application/json
{
    "registrantKey":5678,
    "joinUrl":"https://www1.gotomeeting.com/join/123456789/5678"
}

问题是当我运行文件时我得到了输出

The problem is that when i run the file i got output

[
    {
        "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"
    }
]

我正在使用创建网络研讨会URL,为什么我要获取已注册用户的信息?

I am using the create webinar URL, so why am I getting the info of the user that is already registered?

推荐答案

问题已经3岁了,但考虑到CITR目前的惨淡状况IX(现在是LogMeIn)API文档,我提供了以下片段作为可能的解决方案:

The question is 3 years old, but considering the present dismal state of the CITRIX (now LogMeIn) API documentation, I'm offering the following snippet as a possible solution:

显然,我们需要管理者密钥和访问令牌数据帐户...

Obviously, we'll need the Organizer Key and Access Token data for our account...

    $organizer_key= '10000000000XXXXXXX';
    $access_token = 'GwsiiPWaJbHIiaIiocxxxxxxxxxx';

获取网络研讨会的最低要求字段(例如从HTML表单),并使用JSON对数据进行编码...

Get the minimum required fields for a webinar (for example from an HTML form) and JSON encode the data...

    $newRegFields = (object) array(
        'firstName' => $_POST[ 'FirstName' ],
        'lastName'  => $_POST[ 'LastName'  ],
        'email'     => $_POST[ 'Email'     ],
    );

    $newRegistrantFields = json_encode( $newRegFields );

    //echo '<br><br>' . $newRegistrantFields;

获取网络研讨会...

Get the Webinar...

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

设置LogMeIn API的URL(不需要 resendConfirmation 选项)...

Set the URL to the LogMeIn API (the resendConfirmation option is not required)...

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

格式化POST标头...

Format our POST headers...

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

设置cURL选项,确保我们使用 CURLOPT_POST,1 指定POST ...

Set our cURL options, ensuring we specify a POST with 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编码数据,无论是服务器错误消息还是注册确认消息。现在,让我们将回复变成一个方便的关联数组...

Our cURL call has returned with JSON encoded data, whether it's a server error message or a confirmation of registration. Now let's turn the reply into a handy associative array...

    $newRegistrantsArray = json_decode( $newRegistrants, true );

    //echo '<br><br>' . $newRegistrants . '<br><br>';
    //echo '<pre>'; print_r( $newRegistrantsArray ); echo '</pre>';

如果返回了 errorCode 键,则注册被炸毁。我在这里所做的只是从服务器获取实际的错误描述并将其加载以返回到我的调用HTML页面,但这完全是可选的...

If the errorCode key was returned, then the registration bombed out. All I'm doing here is grabbing the actual error description from the server and loading it up to return to my calling HTML page, but this is totally optional...

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

现在,如果注册成功,服务器将返回类似内容。 。

Now, if a registration was successful, the server will return something like...

(
  [registrantKey] => 2.5022062212198E+18
  [joinUrl] => https://global.gotowebinar.com/join/6552167171182613761/103193261
) 

。 ..所以我只是在检查是否返回了这些密钥,如果是,我知道注册很好。

...and so I'm just checking to see if those keys were returned, and if so, I know the registration was good.

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

这篇关于如何通过PHP调用CITRIX(LogMeIn)API来注册新的GotoWebinar参与者?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆