Convert cURL command line to PHP cURL

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 tried this, but it does not 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);

the error i get

SSL certificate problem, make sure the CA certificate is in order. Details: error: 14090086: SSL procedures: SSL3_GET_SERVER_CERTIFICATE: certificate verification completed

however it works in the standard curl command

+5
source share
1 answer

You need to provide curl with a certificate chain that will allow it to verify Twitter's SSL certificate as valid. To do this, download the necessary signing certificates from here and save them in a simple file (suppose you name it cacert.pem).

CURLOPT_CAINFO, :

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

SSL , :

curl_setopt($ch, CURLOPT_VERIFYPEER, true);
+2

All Articles