gotowebinar api php [英] gotowebinar api php

查看:72
本文介绍了gotowebinar api php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出php中的gotowebinar api,但没有得到.因此,我尝试编写一个可能有用的简单类.它进行身份验证,与gotowebinar,getomeeting和rest相同.它获取即将举行的网络研讨会,所有网络研讨会,单个网络研讨会信息,注册人字段,并创建注册人.现在大家都可以根据需要对其进行增强.任何建议都非常适合.

help.txt

1) First change the GOTO_WEBINAR_API_KEY in 

gotoWebinarClass.php to your appication key. 

2) Then change the
REDIRECT_URL_AFTER_AUTHENTICATION in 

authorize.php. It is a url where one should be redirected after 

authentication. 

3) Execute authorize.php. 

4) After you autheticate,
it would take you to 

REDIRECT_URL_AFTER_AUTHENTICATION with "code" in the query 

string. 
5) Copy that code and execute the authorize.php again with ?

code='your_code' in the query string. 
6) If everything goes fine, we will get the token and we will set into session and be redirected to get-all-webinars.php 

which fetches user's all webinars.

该课程尚不完整,我已经奠定了基本的

基础,现在您可以继续添加其他功能.任何

来自您这边的建议很可取.谢谢.

gotoWebinarClass.php

<?php

define('GOTO_WEBINAR_API_KEY','your gotowebinar application key');

class OAuth_En{

protected $_accessToken;
protected $_userId;
protected $_organizerKey;
protected $_refreshToken;
protected $_expiresIn;

public function getAccessToken(){
    return $this->_accessToken;
}

public function setAccessToken($token){
    $this->_accessToken = $token;
}

public function getUserId(){
    return $this->_userId;
}

public function setUserId($id){
    $this->_userId = $id;
}   

public function getOrganizerKey(){
    return $this->_organizerKey;
}

public function setOrganizerKey($key){
    $this->_organizerKey = $key;
}

public function getRefreshToken(){
    return $this->_refreshToken;
}

public function setRefreshToken($token){
    $this->_refreshToken = $token;
}

public function getExpiresIn(){
    return $this->_expiresIn;
}

public function setExpiresIn($expiresIn){
    $this->_expiresIn = $expiresIn;
}   


}

class OAuth_Db{
function getToken(){

}       
}

class OAuth{
protected $_redirectUrl;
protected $_OAuthEnObj;
protected $_curlHeader = array();
protected $_apiResponse;
protected $_apiError;
protected $_apiErrorCode;
protected $_apiRequestUrl;
protected $_apiResponseKey;
protected $_accessTokenUrl;
protected $_webinarId;
protected $_registrantInfo = array();
protected $_apiRequestType;
protected $_apiPostData;

public function __construct(OAuth_En $oAuthEn){
    $this->_OAuthEnObj = $oAuthEn;  
}

public function getOAuthEntityClone(){
    return clone $this->_OAuthEnObj;    
}

public function getWebinarId(){
    return $this->_webinarId;
}

public function setWebinarId($id){
    $id = (int)$id;
    $this->_webinarId = empty($id) ? 0 : $id;
}

public function setApiErrorCode($code){
    $this->_apiErrorCode = $code;   
}

public function getApiErrorCode(){
    return $this->_apiErrorCode;    
}   

public function getApiAuthorizationUrl(){
    return 'https://api.citrixonline.com/oauth/authorize?client_id='.GOTO_WEBINAR_API_KEY.'&redirect_uri='.$this->getRedirectUrl(); 
}

public function getApiKey(){
    return  GOTO_WEBINAR_API_KEY;
}

public function getApiRequestUrl(){
    return  $this->_apiRequestUrl;
}

public function setApiRequestUrl($url){
    $this->_apiRequestUrl = $url;
}

public function setRedirectUrl($url){
    $this->_redirectUrl = urlencode($url);  
}

public function getRedirectUrl(){
    return $this->_redirectUrl; 
}

public function setCurlHeader($header){
    $this->_curlHeader = $header;   
}

public function getCurlHeader(){
    return $this->_curlHeader;  
} 

public function setApiResponseKey($key){
    $this->_apiResponseKey = $key;
}

public function getApiResponseKey(){
    return $this->_apiResponseKey;
}

public function setRegistrantInfo($arrInfo){
    $this->_registrantInfo = $arrInfo;  
}

public function getRegistrantInfo(){
    return $this->_registrantInfo;  
}

public function authorizeUsingResponseKey($responseKey){
    $this->setApiResponseKey($responseKey);
    $this->setApiTokenUsingResponseKey();
}

protected function setAccessTokenUrl(){
    $url = 'https://api.citrixonline.com/oauth/access_token?grant_type=authorization_code&code={responseKey}&client_id={api_key}';
    $url = str_replace('{api_key}', $this->getApiKey(), $url);
    $url = str_replace('{responseKey}', $this->getApiResponseKey(), $url);
    $this->_accessTokenUrl = $url;
}

protected function getAccessTokenUrl(){
    return $this->_accessTokenUrl;  
}

protected function resetApiError(){
    $this->_apiError = '';  
}

public function setApiTokenUsingResponseKey(){
    //set the access token url
    $this->setAccessTokenUrl();

    //set the url where api should go for request
    $this->setApiRequestUrl($this->getAccessTokenUrl());

    //make request
    $this->makeApiRequest();

    if($this->hasApiError()){
        echo $this->getApiError();
    }else{
        //if api does not have any error set the token
        echo $this->getResponseData();
        $responseData = json_decode($this->getResponseData());
        $this->_OAuthEnObj->setAccessToken($responseData->access_token);
        $this->_OAuthEnObj->setOrganizerKey($responseData->organizer_key);
        $this->_OAuthEnObj->setRefreshToken($responseData->refresh_token);
        $this->_OAuthEnObj->setExpiresIn($responseData->expires_in);
    }
}

function hasApiError(){
    return $this->getApiError() ? 1 : 0;
}

function getApiError(){
    return $this->_apiError;
}

function setApiError($errors){
    return $this->_apiError = $errors;
}

function getApiRequestType(){
    return $this->_apiRequestType;
}

function setApiRequestType($type){
    return $this->_apiRequestType = $type;
}   

function getResponseData(){
    return $this->_apiResponse;
}

function setApiPostData($data){
    return $this->_apiPostData = $data;
}   

function getApiPostData(){
    return $this->_apiPostData;
}   

function makeApiRequest(){
    $header = array();

    $this->getApiRequestUrl();
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
    curl_setopt($ch, CURLOPT_URL, $this->getApiRequestUrl());
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    if($this->getApiRequestType()=='POST'){
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $this->getApiPostData());  
    }

    if($this->getCurlHeader()){
        $headers = $this->getCurlHeader();
    }else{
        $headers = array(
                "HTTP/1.1",
                "Content-type: application/json",
                "Accept: application/json",
                "Authorization: OAuth oauth_token=".$this->_OAuthEnObj->getAccessToken()
            );  
    }

    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 

    $data = curl_exec($ch);
    $validResponseCodes = array(200,201,409);
    $responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); 

    $this->resetApiError();

    if (curl_errno($ch)) {
        $this->setApiError(array(curl_error($ch)));
    } elseif(!in_array($responseCode, $validResponseCodes)){
        if($this->isJsonString($data)){
            $data = json_decode($data);
        }

        $this->setApiError($data);
        $this->setApiErrorCode($responseCode);
    }else {
        $this->_apiResponse = $data;
        $_SESSION['gotoApiResponse'] = $this->getResponseData();
        curl_close($ch);
    }
}

function isAuthorizationRequiredAgain(){
    $arrAuthorizationRequiredCodes = array(400,401,403,500);
    $isAuthRequired = 0;
    $error = $this->getApiError();
    $responseCode = $this->getApiErrorCode();

    //we might have to add more exception in this condition
    if(in_array($responseCode, $arrAuthorizationRequiredCodes)){
        if($responseCode==400 && is_object($error)){    //because for 400 error sometime one needs to authenticate again
            foreach($error as $single){
                $pos = strpos($single,'Authorization');
                if($pos!==false){
                    $isAuthRequired = 1;
                }
            }
        }else{
            $isAuthRequired = 1;    
        }
    }

    return $isAuthRequired;
}

function getWebinars(){
    $url = 'https://api.citrixonline.com/G2W/rest/organizers/'.$this->_OAuthEnObj->getOrganizerKey().'/webinars';
    $this->setApiRequestUrl($url);
    $this->setApiRequestType('GET');
    $this->makeApiRequest();

    if($this->hasApiError()){
        return null;    
    }

    $webinars = json_decode($this->getResponseData());

    return $webinars;
}

function getWebinar(){
    if(!$this->getWebinarId()){
        $this->setApiError(array('Webinar id not provided'));               
        return null;
    }

    $this->setApiRequestType('GET');
    $url = 'https://api.citrixonline.com/G2W/rest/organizers/'.$this->_OAuthEnObj->getOrganizerKey().'/webinars/'.$this->getWebinarId();
    $this->setApiRequestUrl($url);
    $this->makeApiRequest();

    if($this->hasApiError()){
        return null;    
    }

    $webinar = json_decode($this->getResponseData());

    return $webinar;
}

function getUpcomingWebinars(){
    $url = 'https://api.citrixonline.com/G2W/rest/organizers/'.$this->_OAuthEnObj->getOrganizerKey().'/upcomingWebinars';
    $this->setApiRequestUrl($url);
    $this->setApiRequestType('GET');
    $this->makeApiRequest();

    if($this->hasApiError()){
        return null;    
    }

    $webinars = json_decode($this->getResponseData());

    return $webinars;       
}

function createRegistrant(){
    if(!$this->getWebinarId()){
        $this->setApiError(array('Webinar id not provided'));               
        return null;
    }

    if(!$this->getRegistrantInfo()){
        $this->setApiError(array('Registrant info not provided'));              
        return null;
    }

    $this->setApiRequestType('POST');   
    $this->setApiPostData(json_encode($this->getRegistrantInfo())); 
    $url = 'https://api.citrixonline.com/G2W/rest/organizers/'.$this->_OAuthEnObj->getOrganizerKey().'/webinars/'.$this->getWebinarId().'/registrants';

    $this->setApiRequestUrl($url);
    $this->makeApiRequest();

    if($this->hasApiError()){
        return null;    
    }

    $webinar = json_decode($this->getResponseData());

    return $webinar;
}

function getWebinarRegistrantsFields(){
    if(!$this->getWebinarId()){
        $this->setApiError(array('Webinar id not provided'));               
        return null;
    }
    $url = 'https://api.citrixonline.com/G2W/rest/organizers/'.$this->_OAuthEnObj->getOrganizerKey().'/webinars/'.$this->getWebinarId().'/registrants/fields';
    $this->setApiRequestUrl($url);
    $this->setApiRequestType('GET');
    $this->makeApiRequest();

    if($this->hasApiError()){
        return null;    
    }

    $registrantFields = json_decode($this->getResponseData());

    return $registrantFields;   

}

function isJsonString($string){
    $isJson = 0;
    $decodedString = json_decode($string);
    if(is_array($decodedString) || is_object($decodedString))
        $isJson = 1;    

    return $isJson;
}
}

Authorize.php

<?php
include_once "gotoWebinarClass.php";
define('REDIRECT_URL_AFTER_AUTHENTICATION','http://url where we want to redirect'); //this is the url where your get token code would be written.

session_start();
$obj = new OAuth_En();

$oauth = new OAuth($obj);


if(!isset($_GET['code'])){  
    goForAuthorization();
}else{  //when user authenticates and redirect back to application redirect url, get the token
    $oauth->authorizeUsingResponseKey($_GET['code']);
    if(!$oauth->hasApiError()){
        $objOAuthEn = $oauth->getOAuthEntityClone();
        $_SESSION['oauthEn'] = serialize($objOAuthEn);
        header('Location: get-all-webinars.php');       
    }
}

//this function has been used for getting the key using which we can get the access token and organizer key
function goForAuthorization(){
    global $oauth;
    $oauth->setRedirectUrl(REDIRECT_URL_AFTER_AUTHENTICATION);
    $url = $oauth->getApiAuthorizationUrl();
    header('Location: '.$url);
}

get-all-webinars.php

<?php

include_once "gotoWebinarClass.php";
session_start();
$obj = unserialize($_SESSION['oauthEn']);

/*
this can be used to fetch the stored access token key and organizer key from database and use it without asking the authetication from user again

$obj = new OAuth_En();
$obj->setAccessToken('token');
$obj->setOrganizerKey('organizer key');
*/

$oauth = new OAuth($obj);
$webinars = $oauth->getWebinars();

echo '<pre>';
if(!$oauth->hasApiError()){
    print_r($webinars); 
}else{
    print_r($oauth->getApiError()); 
}
exit;

/*$webinars = $oauth->getUpcomingWebinars();

if(!$oauth->hasApiError()){
    print_r($webinars); 
}else{
    print_r($oauth->getApiError()); 
}

exit;
$registrantInfo = array(
    "firstName"=>"ashish",
    "lastName"=>"mehta",
    "email"=>"test@test.com",
);

$oauth->setWebinarId(525120321);
$oauth->setRegistrantInfo($registrantInfo);

$res = $oauth->createRegistrant();
echo $oauth->getApiErrorCode();
if(!$oauth->hasApiError()){
    print_r($res);  
}else{
    echo 'error';
    print_r($oauth->getApiError()); 
}

exit;
$oauth->setWebinarId(525120321);
$webinar = $oauth->getWebinar();

if(!$oauth->hasApiError()){
    print_r($webinar);  

}else{
    print_r($oauth->getApiError()); 
    echo $oauth->getApiErrorCode();
}
*/

解决方案

我一直在尝试此类,它确实很有帮助而且很棒. :)

我遇到的唯一问题是,当它重定向到GotoWebinar时,它将首先要求我输入用户名和密码,然后返回包含即将举行的网络研讨会的Array.

是否有一种方法可以通过使用POST或任何其他代码自动登录到GotoWebinar,这样我就不必手动输入用户名和密码了?这是我当前的authorize.php代码.

我尝试了直接登录, https://developer.citrixonline.com/page/direct-登录.但是,它将返回我的用户帐户的信息.但是它不会重定向到将生成网络研讨会的页面.

非常感谢!

I tried to find out gotowebinar api in php but didn't get it. So, I have tried to write a simple class which can be useful. It does authentication which is same for gotowebinar, gotomeeting and rest. It fetches the upcoming webinar, all webinars, single webinar information, registrants fields and also create registrant. Now you all can enhance it as you want. Any suggestion would be much appericiated.

help.txt

1) First change the GOTO_WEBINAR_API_KEY in 

gotoWebinarClass.php to your appication key. 

2) Then change the
REDIRECT_URL_AFTER_AUTHENTICATION in 

authorize.php. It is a url where one should be redirected after 

authentication. 

3) Execute authorize.php. 

4) After you autheticate,
it would take you to 

REDIRECT_URL_AFTER_AUTHENTICATION with "code" in the query 

string. 
5) Copy that code and execute the authorize.php again with ?

code='your_code' in the query string. 
6) If everything goes fine, we will get the token and we will set into session and be redirected to get-all-webinars.php 

which fetches user's all webinars.

This class is not complete, I have laid down the basic

foundation, now you can keep on adding the other functions. Any

suggestion from your side would be much appriciated. Thanks.

gotoWebinarClass.php

<?php

define('GOTO_WEBINAR_API_KEY','your gotowebinar application key');

class OAuth_En{

protected $_accessToken;
protected $_userId;
protected $_organizerKey;
protected $_refreshToken;
protected $_expiresIn;

public function getAccessToken(){
    return $this->_accessToken;
}

public function setAccessToken($token){
    $this->_accessToken = $token;
}

public function getUserId(){
    return $this->_userId;
}

public function setUserId($id){
    $this->_userId = $id;
}   

public function getOrganizerKey(){
    return $this->_organizerKey;
}

public function setOrganizerKey($key){
    $this->_organizerKey = $key;
}

public function getRefreshToken(){
    return $this->_refreshToken;
}

public function setRefreshToken($token){
    $this->_refreshToken = $token;
}

public function getExpiresIn(){
    return $this->_expiresIn;
}

public function setExpiresIn($expiresIn){
    $this->_expiresIn = $expiresIn;
}   


}

class OAuth_Db{
function getToken(){

}       
}

class OAuth{
protected $_redirectUrl;
protected $_OAuthEnObj;
protected $_curlHeader = array();
protected $_apiResponse;
protected $_apiError;
protected $_apiErrorCode;
protected $_apiRequestUrl;
protected $_apiResponseKey;
protected $_accessTokenUrl;
protected $_webinarId;
protected $_registrantInfo = array();
protected $_apiRequestType;
protected $_apiPostData;

public function __construct(OAuth_En $oAuthEn){
    $this->_OAuthEnObj = $oAuthEn;  
}

public function getOAuthEntityClone(){
    return clone $this->_OAuthEnObj;    
}

public function getWebinarId(){
    return $this->_webinarId;
}

public function setWebinarId($id){
    $id = (int)$id;
    $this->_webinarId = empty($id) ? 0 : $id;
}

public function setApiErrorCode($code){
    $this->_apiErrorCode = $code;   
}

public function getApiErrorCode(){
    return $this->_apiErrorCode;    
}   

public function getApiAuthorizationUrl(){
    return 'https://api.citrixonline.com/oauth/authorize?client_id='.GOTO_WEBINAR_API_KEY.'&redirect_uri='.$this->getRedirectUrl(); 
}

public function getApiKey(){
    return  GOTO_WEBINAR_API_KEY;
}

public function getApiRequestUrl(){
    return  $this->_apiRequestUrl;
}

public function setApiRequestUrl($url){
    $this->_apiRequestUrl = $url;
}

public function setRedirectUrl($url){
    $this->_redirectUrl = urlencode($url);  
}

public function getRedirectUrl(){
    return $this->_redirectUrl; 
}

public function setCurlHeader($header){
    $this->_curlHeader = $header;   
}

public function getCurlHeader(){
    return $this->_curlHeader;  
} 

public function setApiResponseKey($key){
    $this->_apiResponseKey = $key;
}

public function getApiResponseKey(){
    return $this->_apiResponseKey;
}

public function setRegistrantInfo($arrInfo){
    $this->_registrantInfo = $arrInfo;  
}

public function getRegistrantInfo(){
    return $this->_registrantInfo;  
}

public function authorizeUsingResponseKey($responseKey){
    $this->setApiResponseKey($responseKey);
    $this->setApiTokenUsingResponseKey();
}

protected function setAccessTokenUrl(){
    $url = 'https://api.citrixonline.com/oauth/access_token?grant_type=authorization_code&code={responseKey}&client_id={api_key}';
    $url = str_replace('{api_key}', $this->getApiKey(), $url);
    $url = str_replace('{responseKey}', $this->getApiResponseKey(), $url);
    $this->_accessTokenUrl = $url;
}

protected function getAccessTokenUrl(){
    return $this->_accessTokenUrl;  
}

protected function resetApiError(){
    $this->_apiError = '';  
}

public function setApiTokenUsingResponseKey(){
    //set the access token url
    $this->setAccessTokenUrl();

    //set the url where api should go for request
    $this->setApiRequestUrl($this->getAccessTokenUrl());

    //make request
    $this->makeApiRequest();

    if($this->hasApiError()){
        echo $this->getApiError();
    }else{
        //if api does not have any error set the token
        echo $this->getResponseData();
        $responseData = json_decode($this->getResponseData());
        $this->_OAuthEnObj->setAccessToken($responseData->access_token);
        $this->_OAuthEnObj->setOrganizerKey($responseData->organizer_key);
        $this->_OAuthEnObj->setRefreshToken($responseData->refresh_token);
        $this->_OAuthEnObj->setExpiresIn($responseData->expires_in);
    }
}

function hasApiError(){
    return $this->getApiError() ? 1 : 0;
}

function getApiError(){
    return $this->_apiError;
}

function setApiError($errors){
    return $this->_apiError = $errors;
}

function getApiRequestType(){
    return $this->_apiRequestType;
}

function setApiRequestType($type){
    return $this->_apiRequestType = $type;
}   

function getResponseData(){
    return $this->_apiResponse;
}

function setApiPostData($data){
    return $this->_apiPostData = $data;
}   

function getApiPostData(){
    return $this->_apiPostData;
}   

function makeApiRequest(){
    $header = array();

    $this->getApiRequestUrl();
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
    curl_setopt($ch, CURLOPT_URL, $this->getApiRequestUrl());
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    if($this->getApiRequestType()=='POST'){
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $this->getApiPostData());  
    }

    if($this->getCurlHeader()){
        $headers = $this->getCurlHeader();
    }else{
        $headers = array(
                "HTTP/1.1",
                "Content-type: application/json",
                "Accept: application/json",
                "Authorization: OAuth oauth_token=".$this->_OAuthEnObj->getAccessToken()
            );  
    }

    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 

    $data = curl_exec($ch);
    $validResponseCodes = array(200,201,409);
    $responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); 

    $this->resetApiError();

    if (curl_errno($ch)) {
        $this->setApiError(array(curl_error($ch)));
    } elseif(!in_array($responseCode, $validResponseCodes)){
        if($this->isJsonString($data)){
            $data = json_decode($data);
        }

        $this->setApiError($data);
        $this->setApiErrorCode($responseCode);
    }else {
        $this->_apiResponse = $data;
        $_SESSION['gotoApiResponse'] = $this->getResponseData();
        curl_close($ch);
    }
}

function isAuthorizationRequiredAgain(){
    $arrAuthorizationRequiredCodes = array(400,401,403,500);
    $isAuthRequired = 0;
    $error = $this->getApiError();
    $responseCode = $this->getApiErrorCode();

    //we might have to add more exception in this condition
    if(in_array($responseCode, $arrAuthorizationRequiredCodes)){
        if($responseCode==400 && is_object($error)){    //because for 400 error sometime one needs to authenticate again
            foreach($error as $single){
                $pos = strpos($single,'Authorization');
                if($pos!==false){
                    $isAuthRequired = 1;
                }
            }
        }else{
            $isAuthRequired = 1;    
        }
    }

    return $isAuthRequired;
}

function getWebinars(){
    $url = 'https://api.citrixonline.com/G2W/rest/organizers/'.$this->_OAuthEnObj->getOrganizerKey().'/webinars';
    $this->setApiRequestUrl($url);
    $this->setApiRequestType('GET');
    $this->makeApiRequest();

    if($this->hasApiError()){
        return null;    
    }

    $webinars = json_decode($this->getResponseData());

    return $webinars;
}

function getWebinar(){
    if(!$this->getWebinarId()){
        $this->setApiError(array('Webinar id not provided'));               
        return null;
    }

    $this->setApiRequestType('GET');
    $url = 'https://api.citrixonline.com/G2W/rest/organizers/'.$this->_OAuthEnObj->getOrganizerKey().'/webinars/'.$this->getWebinarId();
    $this->setApiRequestUrl($url);
    $this->makeApiRequest();

    if($this->hasApiError()){
        return null;    
    }

    $webinar = json_decode($this->getResponseData());

    return $webinar;
}

function getUpcomingWebinars(){
    $url = 'https://api.citrixonline.com/G2W/rest/organizers/'.$this->_OAuthEnObj->getOrganizerKey().'/upcomingWebinars';
    $this->setApiRequestUrl($url);
    $this->setApiRequestType('GET');
    $this->makeApiRequest();

    if($this->hasApiError()){
        return null;    
    }

    $webinars = json_decode($this->getResponseData());

    return $webinars;       
}

function createRegistrant(){
    if(!$this->getWebinarId()){
        $this->setApiError(array('Webinar id not provided'));               
        return null;
    }

    if(!$this->getRegistrantInfo()){
        $this->setApiError(array('Registrant info not provided'));              
        return null;
    }

    $this->setApiRequestType('POST');   
    $this->setApiPostData(json_encode($this->getRegistrantInfo())); 
    $url = 'https://api.citrixonline.com/G2W/rest/organizers/'.$this->_OAuthEnObj->getOrganizerKey().'/webinars/'.$this->getWebinarId().'/registrants';

    $this->setApiRequestUrl($url);
    $this->makeApiRequest();

    if($this->hasApiError()){
        return null;    
    }

    $webinar = json_decode($this->getResponseData());

    return $webinar;
}

function getWebinarRegistrantsFields(){
    if(!$this->getWebinarId()){
        $this->setApiError(array('Webinar id not provided'));               
        return null;
    }
    $url = 'https://api.citrixonline.com/G2W/rest/organizers/'.$this->_OAuthEnObj->getOrganizerKey().'/webinars/'.$this->getWebinarId().'/registrants/fields';
    $this->setApiRequestUrl($url);
    $this->setApiRequestType('GET');
    $this->makeApiRequest();

    if($this->hasApiError()){
        return null;    
    }

    $registrantFields = json_decode($this->getResponseData());

    return $registrantFields;   

}

function isJsonString($string){
    $isJson = 0;
    $decodedString = json_decode($string);
    if(is_array($decodedString) || is_object($decodedString))
        $isJson = 1;    

    return $isJson;
}
}

Authorize.php

<?php
include_once "gotoWebinarClass.php";
define('REDIRECT_URL_AFTER_AUTHENTICATION','http://url where we want to redirect'); //this is the url where your get token code would be written.

session_start();
$obj = new OAuth_En();

$oauth = new OAuth($obj);


if(!isset($_GET['code'])){  
    goForAuthorization();
}else{  //when user authenticates and redirect back to application redirect url, get the token
    $oauth->authorizeUsingResponseKey($_GET['code']);
    if(!$oauth->hasApiError()){
        $objOAuthEn = $oauth->getOAuthEntityClone();
        $_SESSION['oauthEn'] = serialize($objOAuthEn);
        header('Location: get-all-webinars.php');       
    }
}

//this function has been used for getting the key using which we can get the access token and organizer key
function goForAuthorization(){
    global $oauth;
    $oauth->setRedirectUrl(REDIRECT_URL_AFTER_AUTHENTICATION);
    $url = $oauth->getApiAuthorizationUrl();
    header('Location: '.$url);
}

get-all-webinars.php

<?php

include_once "gotoWebinarClass.php";
session_start();
$obj = unserialize($_SESSION['oauthEn']);

/*
this can be used to fetch the stored access token key and organizer key from database and use it without asking the authetication from user again

$obj = new OAuth_En();
$obj->setAccessToken('token');
$obj->setOrganizerKey('organizer key');
*/

$oauth = new OAuth($obj);
$webinars = $oauth->getWebinars();

echo '<pre>';
if(!$oauth->hasApiError()){
    print_r($webinars); 
}else{
    print_r($oauth->getApiError()); 
}
exit;

/*$webinars = $oauth->getUpcomingWebinars();

if(!$oauth->hasApiError()){
    print_r($webinars); 
}else{
    print_r($oauth->getApiError()); 
}

exit;
$registrantInfo = array(
    "firstName"=>"ashish",
    "lastName"=>"mehta",
    "email"=>"test@test.com",
);

$oauth->setWebinarId(525120321);
$oauth->setRegistrantInfo($registrantInfo);

$res = $oauth->createRegistrant();
echo $oauth->getApiErrorCode();
if(!$oauth->hasApiError()){
    print_r($res);  
}else{
    echo 'error';
    print_r($oauth->getApiError()); 
}

exit;
$oauth->setWebinarId(525120321);
$webinar = $oauth->getWebinar();

if(!$oauth->hasApiError()){
    print_r($webinar);  

}else{
    print_r($oauth->getApiError()); 
    echo $oauth->getApiErrorCode();
}
*/

解决方案

I've been trying this class and it is really helpful and great. :)

The only problem I am encountering is that when it redirects to GotoWebinar, it would first ask me to enter my username and password before it returns the Array containing the upcoming webinars.

Is there a way to auto-login to GotoWebinar by using POST or any other code so that I won't have to manually enter the username and password? Here is my current code for the authorize.php.

I tried the Direct Login, https://developer.citrixonline.com/page/direct-login. However, it would return the information of my user account. But it would not redirect to the page that will generate the webinars.

Thanks a lot!

这篇关于gotowebinar api php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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