1

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.

Glenn Curtis
  • 659
  • 1
  • 15
  • 32

2 Answers2

3

Did you install also php5-curl?

sudo apt-get install php5-curl

Don't forget to restart apache.

Guillermo Mansilla
  • 3,779
  • 2
  • 29
  • 34
  • Yes, at the start of my question I do state that its installed and working! As I say the 1st code block works with no errors and displays my timeline! But something in Cake is not working with the plugin or its just stopping CURL from working right? I just can't see way it would do something like that? – Glenn Curtis Nov 13 '13 at 00:25
  • 1
    when you say you know Curl is working it's because you used in a command line or because you actually used with PHP? – Guillermo Mansilla Nov 13 '13 at 01:01
1

Having Curl installed and having php5-curl extension installed are two different things.

Chris Pierce
  • 706
  • 5
  • 9
  • Yes you are right, this is the problem with coding when your half asleep! I think I was checking for CURL and not the PHP5, I check this out but I think this should fix it. But its odd as I thought that I had this installed on all of my virtual machines. Glenn. – Glenn Curtis Nov 13 '13 at 09:35