2014-03-27 12 views
0

所以我试图用https://www.gosquared.com API和文档的交互:站点令牌与codeigniter休息。

https://www.gosquared.com/developer/api/now/v3/aggregateStats/

我现在用笨与RESTCURL我有以下代码:

public function __construct() 
{ 
    parent::__construct(); 

    $this->load->library('admin/curl'); 
    $this->load->library('admin/rest'); 

    $this->rest->initialize(array(
     'server' => 'https://api.gosquared.com/now/v3', 
    )); 

    $this->rest->api_key('0000000000000000'); 
    $this->rest->site_token('FFF-000000-F'); 
} 

public function index() 
{ 
    $result = $this->rest->get('aggregateStats'); 
    var_dump($result); 
} 

所以,这正在与服务进行交互,除了在api键之外,该服务还需要site_token才能访问我的信息。

随着代码我现在已经$this->rest->site_token('FFF-000000-F');我得到这个具体的错误,当我加载页面:

Fatal error: Call to undefined method REST::site_token() 

如果我删除的代码行造成的错误,我得到这个作为var_dump($result);结果(因为该网站令牌未获得通过)

object(stdClass)#27 (2) { ["code"]=> int(4000) ["message"]=> string(162) "You must specify a site token. It looks like GSN-1234567-X and can be found in the developer section of your account area https://www.gosquared.com/home/developer" } 

所以我的问题是:

如何在codeigniter中将额外变量site_token传递到rest library而不会收到任何错误?

根据该文件与该API进行交互看起来像一个有效的URL如下(为它的价值)

https://api.gosquared.com/now/v3/aggregateStats?api_key=0000000000000000&site_token=FFF-000000-F 

回答

0

通过将API密钥和site_key到一个数组中的实际请求,我能够使它工作。

// Removed these lines of code: 
$this->rest->api_key('0000000000000000'); 
$this->rest->site_token('FFF-000000-F'); 

// Replaced the $result = $this->rest->get('aggregateStats'); with the following: 
$data['result'] = $this->rest->get('aggregateStats', array('api_key' => '0000000000000000','site_token' => 'FFF-000000-F')); 

只是一个侧面说明,可以考虑将API密钥和站点标记为配置文件为今后更容易更新。