douqujin2767 2012-05-07 07:22
浏览 94

如何获得Citrix Gotomeeting Access Token

Hi i am trying to get Goto meeting OAuth access token via php curl. but it returns nothing when i make a call. please guide me how i can get it, Code is given below.

$api_key = "123456"; $redirect_url = urlencode("URL");

$webinar_url = "https://api.citrixonline.com/oauth/authorize?client_id=".$api_key."&redirect_uri=".$redirect_url;

function getWebinarData($link) { $headers = array( "HTTP/1.1", "Content-type: application/json", "Accept: application/json" );

$curl = curl_init($link);

curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);      //2

$response = curl_exec($curl);
echo "<pre>DATA: ";print_r($response);echo "</pre>";
curl_close($curl);

return $response;

}

  • 写回答

1条回答 默认 最新

  • donglianer5064 2013-02-13 05:20
    关注
    /**
     * goto api 
     * Author: Ahad Ali
     * Date: valentines day 2013 
     * Classes Curl, OAuth, GotoTraining
     */
    define ("API_KEY", "");
    define ("REDIRECT_URL","");
    define ("AUTH_AUTOLOGIN_URL","https://developer.citrixonline.com/oauth/g2t/authorize.php");
    define ("AUTH_EXCHANGE_URL", "https://api.citrixonline.com/oauth/access_token?grant_type=authorization_code&code=<CODE>&client_id=" . API_KEY);
    define ("MANAGE_TRAINING_URL","https://api.citrixonline.com/G2T/rest/organizers/<ORGANIZERKEY>/trainings");
    
    class Curl
    {
        public $result;
        public function __construct()
        {
    
        }
    
        public function request($url, $data="", $method="get", $headers="")
        {
            $ch = curl_init();
            // this is autologiM USING CURL POST
            // avoiding the redirect to gotos site where it asks for email and password and redirects back to the URL with a code
            curl_setopt($ch, CURLOPT_URL, $url); 
            if($method == "post")
            {
                curl_setopt($ch, CURLOPT_POST, true);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
                curl_setopt($ch, CURLOPT_HEADER, true);
            }
            if($headers)
                curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);          
    
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    
            $this->result =  (string) curl_exec($ch);
            curl_close($ch);
            return $this->result;
        }
    
        public function __destruct()
        {
    
        }
    }
    
    class OAuth
    {
        public $autologin_url;
        public $exchange_url;
        public $code;
        public $auth_result;
        //https://api.citrixonline.com/oauth/authorize?client_id= used this URL to get all the field names 
       public $login_data = array(
            'emailAddress' => '',
            'password' => '',
            'client_id' => '',
            'access_type'=> 'G2T',
            'app_name' => '',
            'redirect_uri' => '',
            'submitted' => 'form_submitted',
            );
    
       public function __construct($autologin_url = AUTH_AUTOLOGIN_URL, $exchange_url = AUTH_EXCHANGE_URL, $apikey=API_KEY)
       {
           $this->autologin_url = $autologin_url;
           $this->exchange_url = $exchange_url;
           $this->login_data['client_id'] = $apikey;
       }
       public function authorize()
       {
           $this->getCode();
           $this->exchangeCodeForAccessToken();
    
       }
       public function getCode()
       {
           $curl = new Curl();
           $result = $curl->request($this->autologin_url, $this->login_data, "post");
           $arr = explode("
    ", $result);
            foreach($arr as $k=>$v)
            {
                    if(strstr($v,"Location: http:"))
                            $return_url = $v;
            }
            $query = trim(parse_url($return_url, PHP_URL_QUERY));// adds one unnecessary _ (underscore) at the end of the query string
            $this->code = substr($query, 5, (strlen($query) - 6));//starting from 5 get me ...number of chars
       }
       function exchangeCodeForAccessToken()
       {
           $this->exchange_url = str_replace("<CODE>", $this->code, $this->exchange_url);
           $curl = new Curl();
           $result = $curl->request($this->exchange_url);
           $this->auth_result = json_decode($result);
        }
       public function __destruct()
       {
    
       }
    }
    
    class GotoTraining extends OAuth
    {
        public $manage_training_url;
        public $training_result;
        public $error_list = array("AuthFailure", "AccessDenied", "ExpiredToken", "InternalError", "InvalidRequest", "InvalidMethod", "MissingToken", "NoSuchTraining", "InvalidToken");
        public function __construct($url = MANAGE_TRAINING_URL)
        {
            $this->manage_training_url = $url;
            parent::__construct();
        }
        /**
     *Arguement List for goto CreateTraining service
     *  [name] => Representational State Transfer 101
        [description] => The REST-ful way to APIs.
        [timeZone] => America/Los_Angeles
        [times] => Array
            (
                [0] => stdClass Object
                    (
                        [startDate] => 2011-09-08T18:25:00Z
                        [endDate] => 2011-09-08T19:25:00Z
                    )
    
                [1] => stdClass Object
                    (
                        [startDate] => 2011-09-09T18:25:00Z
                        [endDate] => 2011-09-09T19:25:00Z
                    )
    
            )
    
        [registrationSettings] => stdClass Object
            (
                [disableWebRegistration] => false
                [disableConfirmationEmail] => false
            )
    
        [organizers] => Array
            (
                [0] => 6512477
                [1] => 38712
                [2] => 9876466
            ) 
     */
        public function createTraining($name, $desc, $times)
        {
    
            $registrationSettings["disableWebRegistration"] = "false";
            $registrationSettings["disableConfirmationEmail"] = "false";
    
            $json["name"] = $name;
            $json["description"] = $desc;
            $json["timeZone"] = "Australia/Sydney";
            $json["times"] = $times;//array for startDate, endDate
            $json["registrationSettings"] = $registrationSettings;
            $json["organizers"][0] =  $this->auth_result->organizer_key;
    
            $this->manage_training_url = str_replace("<ORGANIZERKEY>", $this->auth_result->organizer_key, $this->manage_training_url);
            $json = json_encode($json);
            //$post_data[] = "Authorization:OAuth oauth_token=" . $this->auth_result->access_token;
            //$this->manage_training_url = $this->manage_training_url . "?oauth_token=" . $this->auth_result->access_token;
    
            $headers =  array(
                   'Accept: application/json',
                  'Content-Type: application/json', 
                  'Authorization: OAuth oauth_token=' . $this->auth_result->access_token
                  );
    
            //$this->manage_training_url = $this->manage_training_url . "?oauth_token=" . $this->auth_result->access_token;
            $curl = new Curl();
            $this->training_result = $curl->request($this->manage_training_url, $json, "post", $headers);
            $arr = explode("
    ", $this->training_result);
            $this->webCode = trim($arr[count($arr)-1], '"');
    
            $this->checkError();
    
            return $this->webCode;
        }
    
        public function checkError()
        {
            foreach($this->error_list as $val)
            {
                if(strstr($this->training_result, $val))
                    $this->webCode = $val;
            }
            return 0;
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大