facebook - Translating cURL request with -G to PHP -


i'm trying use facebook marketing api detailed in this tutorial.

however i'm stumped how translate suggested curl command line request it's php equivalent:

curl -g \ -d 'access_token=<access_token>' \ https://graph.facebook.com/v2.5/<lead_id> 

i this:

$ch = curl_init();  curl_setopt($ch,curlopt_url,$url); curl_setopt($ch,curlopt_post,1); curl_setopt($ch,curlopt_postfields,$access_token);  $result = curl_exec($ch); 

but produces 'unsupported post request' error when attempting run it. think misunderstanding '-g' means in command line version?

from man curl:

-g, --get

when used, option make data specified -d, --data, --data-binary or --data-urlencode used in http request instead of post request otherwise used. data appended url '?' separator.

there's no curl option flag in php directly corresponds this. can use

curl_setopt($ch, curlopt_customrequest, 'get'); 

or

curl_setopt($ch, curlopt_httpget, 'get'); 

but hardly necessary:

curlopt_httpget

true reset http request method get. since default, necessary if request method has been changed.

you have specify request parameters differently: instead of setting curlopt_postfields, append them query string url (using urlencode or equivalent curl_escape if needed):

curl_setopt( $ch, curlopt_url, $url . '?accesstoken='.urlencode('<access_token>'); 

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -