Ich habe versucht, Json von meinem Google-Blatt mit Curl in PHP zu bekommen. Daten werden jedoch nicht angezeigt.nicht in der Lage, Json von Google-Blatt mit Hilfe von Curl in PHP zu bekommen
dies ist mein Code:
$feed = "https://docs.google.com/spreadsheets/d/1h2fIi74s-1fypmZWkOGSwJh1ih9pfcOwQ81KTTiAfIU/edit#gid=2053646480";
$curl = curl_init($feed);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
$curl_response = curl_exec($curl);
curl_close($curl);
$curl_json = json_decode($curl_response, true);
print_r($curl_json);
, bevor ich hatte es mit fopen getan (erhaltener Code frm einige Forum) jetzt hat es deaktiviert wurde, obwohl url_fopen in der php.ini-Datei und auf der Suche nach einer Alternative aktiviert ist als Ich möchte das gleiche Ergebnis wie zuvor.
<?php
//header('Content-type: application/json');
// Set your CSV feed
$feed = 'https://docs.google.com/spreadsheets/d/1sIq64_3lg9mNxidpClqdjZCZgOPbh8etCRml2cYHXeg/export?format=csv&id=1sIq64_3lg9mNxidpClqdjZCZgOPbh8etCRml2cYHXeg&gid=1790778854';
// Arrays we'll use later
$keys = array();
$newArray = array();
// Function to convert CSV into associative array
function csvToArray($file, $delimiter) {
if (($handle = fopen($file, 'r')) !== FALSE) {
$i = 0;
while (($lineArray = fgetcsv($handle, 4000, $delimiter, '"')) !== FALSE) {
for ($j = 0; $j < count($lineArray); $j++) {
$arr[$i][$j] = $lineArray[$j];
}
$i++;
}
fclose($handle);
}
return $arr;
}
// Do it
$data = csvToArray($feed, ',');
// Set number of elements (minus 1 because we shift off the first row)
$count = count($data) - 1;
//Use first row for names
$labels = array_shift($data);
foreach ($labels as $label) {
$keys[] = $label;
}
// Add Ids, just in case we want them later
/*$keys[] = 'id';
for ($i = 0; $i < $count; $i++) {
$data[$i][] = $i;
}
*/
// Bring it all together
for ($j = 0; $j < $count; $j++) {
$d = array_combine($keys, $data[$j]);
$newArray[$j] = $d;
}
// Print it out as JSON
echo json_encode($newArray);
?>
Zuerst drucken Sie diese $ curl_response und überprüfen Sie, ob die Antwort in JSON ist. –
diese URL gibt json nicht zurück, aber etwas html mit eingebetteter js. – YvesLeBorg
was wäre die lösung ?? –