5

I need to translate this cURL command into PHP cURL code:

> curl --get 'https://api.twitter.com/1/followers/ids.json' --data
> 'cursor=-1&screen_name=somename' --header 'Authorization: OAuth
> oauth_consumer_key="key", oauth_nonce="nonce",
> oauth_signature="signature", oauth_signature_method="HMAC-SHA1",
> oauth_timestamp="timestamp", oauth_token="token", oauth_version="1.0"'
> --verbose

I have tried this, but it doesn't seem to work:

> $ch = curl_init();
> curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: OAuth oauth_consumer_key="key", oauth_nonce="nonce", oauth_signature="signature", oauth_signature_method="HMAC-SHA1", oauth_timestamp="timestamp", oauth_token="token", oauth_version="1.0"'));
> curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
> curl_setopt($ch, CURLOPT_VERBOSE, 1);
> curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
> curl_setopt($ch, CURLOPT_HTTPGET, 1);
> curl_setopt($ch, CURLOPT_URL, 'https://api.twitter.com/1/users/show.json?cursor=-1&screen_name=somename');
> $page = curl_exec($ch);
> curl_close($ch);

error i am getting

SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

however it works in the standard curl command

1

1 Answer 1

2

You need to provide curl with the certificate chain that will allow it to verify Twitter's SSL certificate as valid. To do this, download the requisite certificate signatures from here and save them into a plain file (I 'll assume you name it cacert.pem).

Then, before making the request, set CURLOPT_CAINFO to point to this file:

// assumes file in same directory as script
curl_setopt($ch, CURLOPT_CAINFO, 'cacert.pem');

It's also a good idea to explicitly enable SSL certificate verification instead of relying on default settings:

curl_setopt($ch, CURLOPT_VERIFYPEER, true);
Sign up to request clarification or add additional context in comments.

2 Comments

Now I get this error: setting certificate verify locations: CAfile: cacert.pem CApath: none What can I do with that?
@loudislav: Hmm, maybe you need to set CURLOPT_CAPATH to . as well (assuming certificate file in current directory). Also make triple sure that the path for the cert file is correct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.