简体   繁体   中英

CakePHP with Twitter timeline, using twitteroauth, getting curl_init() error?

ok, before I start I am building this in a virtual box running with Ubuntu which does have CURL installed and working!

So reading a number of blog posts and help sites, I used the following code to build pull in my timeline from twitter,

    require_once("twitteroauth.php");

    $twitteruser = "MY-TWITTER-NAME";
    $notweets = 30;
    $consumerkey = "XXXX-XXXXXXX";
    $consumersecret = "XXXX-XXXXXXX";
    $accesstoken = "XXXX-XXXXXXX-XXXX-XXXXXXX";
    $accesstokensecret = "XXXX-XXXXXXXXXXX-XXXXXXXXXXX-XXXXXXX";

    function getConnectionWithAccessToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret) {
      $connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret);
      return $connection;
    }

    $connection = getConnectionWithAccessToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);

    $GetAllMyTweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$twitteruser."&count=".$notweets);

This all works, no problems, the problem is when I try to use it within my CakePHP site, I have the current following code used form a blog I found,

        App::import('Vendor', 'twitteroauth', array('file' => 'twitteroauth'. DS .'twitteroauth.php')); <- outside the controller call

public function Index() {

    $consumerkey = "XXXX-XXXXXXX";
    $consumersecret = "XXXX-XXXXXXX";
    $accesstoken = "XXXX-XXXXXXX-XXXX-XXXXXXX";
    $accesstokensecret = "XXXX-XXXXXXXXXXX-XXXXXXXXXXX-XXXXXXX";



    $Oauth = new TwitterOAuth ($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);

    $Credentials = $Oauth->get("account / verify_credentials ");

    debug($Credentials);
    die();

    //$this->render('/Pages/Main');
}

However I get the following error,

               Error: Call to undefined function curl_init()    
               File: /var/www/app/Vendor/twitteroauth/twitteroauth.php  
               Line: 199

Which I don't understand? What I am doing wrong? Or what I am not doing? Or do I have to pull in a helper or something to let CakePHP work with the CURL?

Please help

Glenn.

Did you install also php5-curl?

sudo apt-get install php5-curl

Don't forget to restart apache.

安装了Curl并安装了php5-curl扩展程序是两回事。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM