Gotomeeting php api(oauth)实现

问题描述 投票:1回答:1

我正在尝试创建一个php gotomeating api实现。我成功获得了access_token但是对于任何其他请求我得到了错误响应。这是我的代码:

<?php 
session_start();

$key = '#';
$secret = '#';

$domain = $_SERVER['HTTP_HOST'];
$base = "/oauth/index.php";
$base_url = urlencode("http://$domain$base");

$OAuth_url = "https://api.citrixonline.com/oauth/authorize?client_id=$key&redirect_uri=$base_url";
$OAuth_exchange_keys_url = "http://api.citrixonline.com/oauth/access_token?grant_type=authorization_code&code={responseKey}&client_id=$key";

if($_SESSION['access_token']) CreateForm();else
if($_GET['send']) OAuth_Authentication($OAuth_url);
elseif($_GET['code']) OAuth_Exchanging_Response_Key($_GET['code'],$OAuth_exchange_keys_url);

function OAuth_Authentication ($url){
    $_SESSION['access_token'] = false;
    header("Location: $url");
}

function CreateForm(){
    $data = getURL('https://api.citrixonline.com/G2M/rest/meetings?oauth_token='.$_SESSION['access_token'],false);
}

function OAuth_Exchanging_Response_Key($code,$url){
    if($_SESSION['access_token']){
        CreateForm();
        return true;
    }
    $data = getURL(str_replace('{responseKey}',$code,$url));

    if(IsJsonString($data)){
        $data = json_decode($data);
        $_SESSION['access_token'] = $data->access_token;
        CreateForm();
    }else{
        echo 'error';
    }
}

/*
 * Helper functions
 */

/*
 * checks if a string is json
 */
function IsJsonString($str){
    try{
        $jObject = json_decode($str);
    }catch(Exception $e){
        return false;
    }
    return (is_object($jObject)) ? true : false;
}
/*
 * CURL function to get url
 */
function getURL($url,$auth_token = false,$data=false){

    // Initialize session and set URL.
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $url);

    // Set so curl_exec returns the result instead of outputting it.
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    if($auth_token){
        curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: OAuth oauth_token='.$auth_token));
    }

    if($data){
        curl_setopt($ch, CURLOPT_POST,true);
        $d = json_encode('{ "subject":"test", "starttime":"2011-12-01T09:00:00Z", "endtime":"2011-12-01T10:00:00Z", "passwordrequired":false, "conferencecallinfo":"test", "timezonekey":"", "meetingtype":"Scheduled" }');

        echo implode('&', array_map('urlify',array_keys($data),$data));
            echo ';';
        curl_setopt($ch, CURLOPT_POSTFIELDS, 
            implode('&', array_map('urlify',array_keys($data),$data))
        );

    }

    // Get the response and close the channel.
    $response = curl_exec($ch);

    /*
     * if redirect, redirect
     */
    $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
                        if ($code == 301 || $code == 302) { 
                            preg_match('/<a href="(.*?)">/', $response, $matches); 
                            $newurl = str_replace('&amp;','&',trim(array_pop($matches))); 
                   $response = getURL($newurl);
                        } else { 
                            $code = 0; 
                        }

    curl_close($ch);

    return $response;
}

function urlify($key, $val) {
  return urlencode($key).'='.urlencode($val);
}

要启动连接过程,您需要向php文件发送请求发送= 1。我尝试了不同的尝试来获得会议列表,但无法得到很好的回应。

有没有人有这方面的问题或知道解决方案?

编辑:

这不是卷曲错误,服务器响应错误消息,在citrix的论坛中他们说它应该工作,没有进一步详细说明为什么它不起作用,如果我对我实现oauth的方式有问题或者请求代码。我得到的最常见错误是:“error code:31305”未在论坛上记录。

php oauth
1个回答
1
投票

[我也在Citrix Developer Forums上发布了这个,但为了完整性,这里也会提到它。]

我们仍在最终确定这些接口的文档,并且实际上需要一些作为可选编写的参数。

与上面的示例相比,所需的更改包括:

  • 将timezonekey设为67(太平洋时间)
  • 将passwordrequired设置为false
  • 将conferencecallinfo设置为Hybrid(意思是:将提供PSTN和VOIP)

考虑到这些更改后,您的示例数据将更像以下内容:

{"subject":"test meeting", "starttime":"2012-02-01T08:00:00",
 "endtime":"2012-02-01T09:00:00", "timezonekey":"67", 
"meetingtype":"Scheduled", "passwordrequired":"false", 
"conferencecallinfo":"Hybrid"}

您还可以查看我创建的PHP示例应用程序:http://pastebin.com/zE77qzAz

© www.soinside.com 2019 - 2024. All rights reserved.