如何在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

duangou2028
duangou2028 你有一个oauth图书馆吗?
4 年多之前 回复

1个回答



你错误地加载一个类作为库加载它</ p>


不存在的类:OAuth </ p>
</ blockquote>

解决方案</ strong> </ p>

只需要在 这样的控制器顶部:</ p>

  require_once(APPPATH.'libraries / OAuth.php'); 
</ code> </ pre>
</ div>

展开原文

原文

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');

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问