/ / PHP Curl Anfrage Schleife keine Ausgabe - PHP, JSON, Curl

PHP Curl Anfrage Schleife keine Ausgabe - PHP, JSON, Curl

Ich baue eine Schleife in PHP, um curl-Anfragen an einen Server zu senden. Ich sende JSON und hoffe, einen Bericht zurückzugeben, der Parameter ausgibt, die in JSON enthalten sind. Mein Code ist wie folgt:

$json = "{"report":{"special_pixel_reporting":false,"report_type":"network_analytics","timezone":"EST5EDT","start_date":"2016-03-01 00:00:00","end_date":"2016-04-01 00:00:00","filters":[{"seller_member_id":["273"]}],"columns":["imps","cost"],"row_per":[],"pivot_report":false,"fixed_columns":[],"show_usd_currency":false,"orders":["imps","cost"],"name":"Network Analytics Report - 04/4/2016","ui_columns":["imps","cost"],"filter_objects":[]}}";

foreach ($results as $k => $v) {
$ch = curl_init("https://api.appnexus.com/report");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Authorization:".$v["token"],
"Content-Type: application/json"));
$output = curl_exec($ch);
var_dump($output);
};

$ results ist ein 2D-Array, das das Authentifizierungstoken enthält (das ich als Iterator verwende). Ich erwarte eine Ausgabe für jedes Token, kann aber keine Antwort vom Server erhalten.

Im Wesentlichen versuche ich diese Curl-Anfrage in PHP zu replizieren.

curl -X POST -d "{"report":{"special_pixel_reporting":false,"report_type":"network_analytics","timezone":"EST5EDT","start_date":"2016-03-01 00:00:00","end_date":"2016-04-01 00:00:00","filters":[{"seller_member_id":["273"]}],"columns":["imps","cost"],"row_per":[],"pivot_report":false,"fixed_columns":[],"show_usd_currency":false,"orders":["imps","cost"],"name":"Network Analytics Report - 04/4/2016","ui_columns":["imps","cost"],"filter_objects":[]}}" --header "Authorization:[AUTH HERE]" https://api.appnexus.com/report

Hat jemand einen Hinweis, warum mein PHP-Code keine Ausgabe liefert?

Antworten:

0 für die Antwort № 1

Vielleicht solltest du nach curl-Fehlern mit nachsehen curl_error()

<?php
$json = "{"report":{"special_pixel_reporting":false,"report_type":"network_analytics","timezone":"EST5EDT","start_date":"2016-03-01 00:00:00","end_date":"2016-04-01 00:00:00","filters":[{"seller_member_id":["273"]}],"columns":["imps","cost"],"row_per":[],"pivot_report":false,"fixed_columns":[],"show_usd_currency":false,"orders":["imps","cost"],"name":"Network Analytics Report - 04/4/2016","ui_columns":["imps","cost"],"filter_objects":[]}}";

foreach ($results as $k => $v) {
$ch = curl_init("https://api.appnexus.com/report");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Authorization:".$v["token"],
"Content-Type: application/json"));

$output = curl_exec($ch);

if($output === false){
echo "Curl error: " . curl_error($ch);
}
else{
var_dump($output);
}
curl_close($ch);
}