Reputation: 1301
I'm making a bot telegram to hear the Jamendo Radio by their API. I wrote this:
$url_radio = 'https://api.jamendo.com/v3.0/radios/stream/?client_id='.CLIENT_ID_J.'&format=jsonpretty&name='.$id;
$result = file_get_contents($url_radio);
$update = json_decode($result, true);
$res = $update['results'];
$sendto =API_URL."sendmessage?chat_id=".$chatID."&text=".urlencode($res[0]['dispname']);
file_get_contents($sendto);
$sendto =API_URL."sendPhoto?chat_id=".$chatID."&photo=".urlencode($res[0]['playingnow']['track_image']);
file_get_contents($sendto);
$name = $res[0]['playingnow']['track_name'].' - '.$res[0]['playingnow']['artist_name'];
$url_track = 'https://api.jamendo.com/v3.0/albums/tracks/?client_id='.CLIENT_ID_J.'&track_id='.$res[0]['playingnow']['track_id'];
$result = file_get_contents($url_track);
$update = json_decode($result, true);
$res = $update['results'][0];
$sendto =API_URL."sendmessage?chat_id=".$chatID."&text=".urlencode($name.chr(10).$res["tracks"][0]['audio']);
file_get_contents($sendto);
It works perfectly, but I would avoid too many calls by: "file_get_contents($sendto);".
is there any alternative way to avoid those 3 calls?
Upvotes: 1
Views: 97
Reputation: 2292
If I understood your problem clearly, you can avoid one query.
SendPhoto API method has caption param. You can use this field for showing $res[0]['dispname']
Upvotes: 1