0

This code is not working:

$ch = curl_init ("https://api.twitter.com/1/statuses/user_timeline/ijustine.json?callback=twitterCallback2&count=4");

curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);

$output = curl_exec ($ch);

var_dump($output);

If I try to access: https://api.twitter.com/1/statuses/user_timeline/ijustine.json?callback=twitterCallback2&count=4

From a browser by typing this address manually it works and json is displayed in browser.

But in my script it's not working.

I am using WAMP and curl extension in PHP (5.3.13) is activated because if I run: var_dump( curl_version() ); I get the array where version is 7.25.0.

Btw. this is working: $ch = curl_init ("http://yahoo.com");

curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);

$output = curl_exec ($ch);

var_dump($output);

But if I try access http://twitter.com I get string '' (length=0). And if I try https://twitter.com I get boolean false Why?

Do I need to enable any additional php extensions or some apache modules on my localhost or something else?

Derfder
  • 3,204
  • 11
  • 50
  • 85
  • 1
    use `http` instead of `https`, otherwise add some `CURLOPT_SSL_*` options. – HamZa May 18 '13 at 15:05
  • possible duplicate of [Can't connect to HTTPS site using cURL. Returns 0 length content instead. What can I do?](http://stackoverflow.com/questions/316099/cant-connect-to-https-site-using-curl-returns-0-length-content-instead-what-c) – dev-null-dweller May 18 '13 at 15:18
  • possible duplicate of [Code does not work without disabling SSL](http://stackoverflow.com/questions/16374126/code-does-not-work-without-disabling-ssl) -- You should use the certificate with it – Baba May 18 '13 at 16:43

2 Answers2

3

This is probably a HTTPS certificate issue; check this past question: Can't connect to HTTPS site using cURL. Returns 0 length content instead. What can I do?

Community
  • 1
  • 1
Patrice Levesque
  • 2,079
  • 17
  • 16
0

It's very important to note that, very soon, your code will no longer work because you are using the twitter api version 1.0, which is deprecated.

This post explains what's going on in a short version.

Once you've read that, you can head over to this post which explains exactly how to get the tokens you require for the 1.1 api.

Again, your code will very shortly cease to work with Twitter's 1.0 api. Your issue will no longer be that of connecting over HTTPS via cURL - you will get a "not authenticated" error on every request.

So use the above information to start using authenticated requests.

Community
  • 1
  • 1
Jimbo
  • 25,790
  • 15
  • 86
  • 131