使用CodeIgniter来调用淘宝SDK数据进行PHP开发

引言


淘宝的开放平台提供了很多语言的SDK,许多开发 者可以方便的利用SDK调用淘宝开放平台的数据,在Web开发方面,http://www.cit.cn/projects/c-cpp /php.html仍然是最热门的开发语言,通过http://www.cit.cn/projects/php/codeigniter.html开发 框架调用淘宝SDK数据应该是一件非常开心的事情。

安装


下载 CodeIgniter的淘宝libraries
解压到application\\libraries\\

使用

申请应用

初始化类库,这里需要到http://open.taobao.com/index.htm注册应用的SDK的app_key及app_secret

初始化类


                $config = array(
                        'app_key'=>'12056677',
                        'secret_key'=>'aa68718a6d55287e70dd3db3a4641340',
                        //'format'      => 'xml'
                );
                $this->load->library('topsdk', $config);这里可以通过$config对sdk进行配置


进行请求

                $this->topsdk->set_request('TaobaokeItemsGetRequest');
                $this->topsdk->setFields("num_iid,title,nick,pic_url,price,click_url,commission,commission_rate,commission_num,commission_volume,shop_click_url,seller_credit_score,item_location,volume");
                $this->topsdk->setPid($this->config->item('taoapi_pid'));
                $this->topsdk->setKeyword("http://www.cit.cn/projects/c-cpp/android.html手机");
                $this->topsdk->setStartCredit("1goldencrown");
                $this->topsdk->setEndCredit("5goldencrown");
                $this->topsdk->setPageSize(8);

通过淘宝SDK提供的方法进行请求,set_request用来设定需要请求的方法,支持的方法可以\\libraries\\TopSdk\\top\\request中查看到。
所调用的字段及相关显示的字段信息可以在http://open.taobao.com/doc/category_list.htm?id=102中查看到。

调用数据


查询完毕后我们可以来显示数据:
$result = $this->topsdk->get_data();              
$this->load->view('android_mobile', $data);在视图中增加

PS:

这个库不知道是什么时候的,topsdk里面的get_data()函数还差一个sessionKey,请打开topsdk.php修改

    public function get_data($sessionKey)
    {
        $resp = $this->top_cilent->execute($this->_req, $sessionKey);
        if ("array" == $this->format) {    
            $resp = $this->_get_object_vars_final($resp);
        }
        return $resp;
    }

 

 

 

posted @ 2012-09-20 15:16  yanqing07  阅读(526)  评论(0编辑  收藏  举报