2011-12-26 85 views
1

我想创建一个php gotomeating api实现。我成功获得了access_token,但对于其他任何请求我都收到了错误响应。这是我的代码:Gotomeeting php api(oauth)实现

<?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文件的请求发送FITH = 1的连接过程。我尝试了不同的尝试来获得会议清单,但无法得到很好的回应。

有没有人有prev问题或知道此解决方案吗?

编辑:

这不是一个错误卷曲,服务器错误消息响应,从思杰他们说,它应该工作的论坛,为什么忽略了最低的工作,如果我有没有进一步的细节问题与我实现oauth或请求代码的方式有关。我得到的最多comon错误是:“error code:31305”,没有在论坛上记录。

+0

*是什么*问题是什么呢?出了什么问题? 'curl_error()'说了些什么? –

+4

嗨,你不应该保密密钥总是一个_secret_?通过张贴在这里,你是公开可见的。 –

+1

******我是幸运的,这是一个模拟帐户:) ty – cuzzea

回答

1

[我还张贴了这个对Citrix Developer Forums,但出于完整性在这里要提到它。]

我们仍在敲定这些接口和它们作为可选实际需要的一些参数的文档。

比起你上面的例子,需要的变化是:

  • 集timezonekey 67(太平洋时间)
  • 集passwordrequired假
  • 集conferencecallinfo到混合(意思是: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

+0

我几乎在那里,ty为回应,但是这给了日期/时间错误,对此有任何想法?顺便说一句,我正在使用模拟账户,这可能会导致问题? – cuzzea