When calling an API endpoint in PHP, what is the difference between passing as a parameter in the URL using
$str = '{\'since\':\'2015-01-01\',\'until\':\'2015-01-22\'}';
'blahblah?access_token=xxx&time_range=' . $str;
versus
$str = '{\'since\':\'2015-01-01\',\'until\':\'2015-01-22\'}';
'blahblah?access_token=xxx&time_range=' . urlencode($str);
Apart from the latter making more likely the URL becoming 'too long'? Knowing that no one is going to see the URL, I just want to retrieve data from the API and output to CSV
Many thanks
via something like this:
$data = array("name" => "Hagrid", "age" => "36");
$data_string = json_encode($data);
$ch = curl_init('http://api.local/rest/users');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
instead of passing this information in the url via a GET request?
Edit: Actually, can someone just tell me where I can read up on curl command line flags like -G, or how to implement the below in PHP? Thanks
curl -G \
-d "fields=['impressions','campaign_group_name','cost_per_action_type']" \
-d "action_breakdowns=['action_type','action_carousel_card_name']" \
-d "level=adgroup" \
-d "access_token=<ACCESS_TOKEN>" \
"https://graph.facebook.com/<API_VERSION>/act_<AD_ACCOUNT_ID>/insights"