【问题标题】:How to use the OAuth Class in codeigniter?如何在 codeigniter 中使用 OAuth 类?
【发布时间】:2017-07-27 18:24:37
【问题描述】:

我正在尝试在 codeigniter 中添加 OAuth 类,但是当我调用它时显示错误

不存在的类:OAuth

这是我的代码

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

}

我也尝试用这种方式添加

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

但还是报错

不存在的类:OAuth

【问题讨论】:

  • 你有oauth库吗?

标签: php codeigniter curl oauth


【解决方案1】:

你错误地加载了一个类作为库加载它像这样

不存在的类:OAuth

解决方案

只需要像这样在控制器顶部加载类:

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

【讨论】:

    猜你喜欢
    • 2020-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多