hej.
so I wanted to write a little script for myself so I can listen to all my vocab reviews, so I looked in to the API v2 (apparently v1 doesnt give out the audio files).
My script works so far, but it is really heavy, as it hast to call a specific ID for each review.
Is there an easier/network friendlier option to get to the audio files?
<?php
$headerTag = "Wanikani-Revision: 20170710";
$authorization = "Authorization: Bearer AUTH TOKEN";
function getVocabularyData($ch, $id, $authorization, $i) {
$url = "https://api.wanikani.com/v2/subjects/" . $id . "/";
//curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', $headerTag ));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', $authorization ));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$vocabulary = json_decode($result, TRUE);
if($vocabulary['object'] == "vocabulary"){
echo "ID : " . $vocabulary['id'] . "<br>";
echo "Meaning : " . $vocabulary['data']['meanings'][0]['meaning']. "<br>";
echo "<audio src=" . $vocabulary['data']['pronunciation_audios'][0]['url'] . " controls ></audio>";
$i = $i +1;
}else{
echo "not a vocabulary" . $vocabulary['object'] . "<br>";
}
echo "<p>";
return $i;
}
$ch = curl_init();
$url = "https://api.wanikani.com/v2/assignments?subject_types=vocabulary";
//$url = "https://api.wanikani.com/v2/reviews";
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', $authorization ));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$decoded = json_decode($result, TRUE);
$i = 0;
foreach ($decoded['data'] as $key => $value) {
if($i<10){
echo $value['data']['subject_id'] . "<br>";
$i = getVocabularyData($ch, $value['data']['subject_id'], $authorization, $i);
}
}
var_dump($decoded);
curl_close($ch);
?>
Thanks,
Phil