dpfz27768 2016-05-26 09:39
浏览 59
已采纳

如何在codeigniter中使用OAuth类?

I'm trying to add the OAuth class in codeigniter but when i call it's show error

Non-existent class: OAuth

This is my code

class Food extends My_Controller
{
    public function __construct(){
        $this->load->library('OAuth');
    }
    public function get_yelp_api(){

    $unsigned_url = "http://api.yelp.com/v2/business/the-waterboy-sacramento";
    $consumer_key = '***********';
    $consumer_secret = '**********';
    $token = '***************';
    $token_secret = '**************';

    $token = new OAuthToken($token, $token_secret);

    $consumer = new OAuthConsumer($consumer_key, $consumer_secret);

    $signature_method = new OAuthSignatureMethod_HMAC_SHA1();

    $oauthrequest = OAuthRequest::from_consumer_and_token($consumer, $token, 'GET', $unsigned_url);

    $oauthrequest->sign_request($signature_method, $consumer, $token);

    $signed_url = $oauthrequest->to_url();

    $ch = curl_init($signed_url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, 0);

    $data = curl_exec($ch);
    curl_close($ch);

    $response = json_decode($data);
    $json_string = file_get_contents($signed_url);
    $result = json_decode($json_string);
    echo '<pre>';
    print_r($result);
    echo '</pre>';
}

}

I also try to add it on this way

require_once(APPPATH.'libraries/OAuth.php');

but still got an error

Non-existent class: OAuth

  • 写回答

1条回答

  • dream5694 2017-07-27 10:24
    关注

    you doing mistake loading a class as library load it like this

    Non-existent class:OAuth

    solution

    just only need to load class at the top of controller like this:

    require_once(APPPATH.'libraries/OAuth.php');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM