RadioDJ - Free Radio Automation Software Forum

TuneIn API Integration

AndyDeGroo

Re: TuneIn API Integration
« Reply #15 on: July 24, 2014, 11:06:55 PM »
I try out the webexport, first the way with the script from Marius to generate default NowPlaying as config in Options, it generate in data.txt the Nowplaying string.
After that i change it to read custom data (see picture) i start up your script and it give the following errors,

Notice: Undefined index: artist in C:\USBWebserver v8.6\root\TuneIn\TuneIn API.php on line 2

Notice: Undefined index: title in C:\USBWebserver v8.6\root\TuneIn\TuneIn API.php on line 3

I don't see anything about the password in that script from you, could that be the problem, i do know nothing from php so i need some help, please.
It has nothing to do with password. It's normal if you see those errors when you open the page in browser. RDJ makes POST request with specified parameters, but by opening the page in browser you are sending GET request without any parameters.
Let me correct that for you:
Code: [Select]
<?php
$artist 
= isset($_POST["artist"]) ? urlencode(stripcslashes($_POST["artist"])) : '';
$title = isset($_POST["title"]) ? urlencode(stripcslashes($_POST["title"])) : '';

if(empty(
$artist) ||empty($title))
    exit(
'No data to send');

$url "http://air.radiotime.com/Playing.ashx?partnerId=<id>&partnerKey=<key>&id=<stationid>&title=".$title."&artist=".$artist;

file_get_contents($url);
?>

Don't forget to replace <id>, <key> and <stationid> with actual values given by TuneIn.

Re: TuneIn API Integration
« Reply #16 on: July 25, 2014, 09:59:40 AM »
Andy,

Thank you for your support, i understand its my lack of knowledge of php, i am now waiting for the partner id and key from TuneIn, i wil take a week or so.

Thanks greetings Nico.

AndyDeGroo

Re: TuneIn API Integration
« Reply #17 on: July 25, 2014, 09:23:55 PM »
Thank you for your support, i understand its my lack of knowledge of php, i am now waiting for the partner id and key from TuneIn, i wil take a week or so.
You're welcome.
For me receiving the API keys took almost three weeks, but it might have been because had I sent my request on December 21st, right before holidays. I received the keys on January 9th.
It seems kinda awkward that somebody on their end has to generate the keys and send them by email instead of allowing broadcasters to register and generate the keys. Most other API services I've used (Twitter, Facebook, Google, etc.) generate keys automatically.

Offline HMC

  • ***
  • 181
Re: TuneIn API Integration
« Reply #18 on: July 26, 2014, 04:44:14 AM »
It has nothing to do with password. It's normal if you see those errors when you open the page in browser. RDJ makes POST request with specified parameters, but by opening the page in browser you are sending GET request without any parameters.
Let me correct that for you:
Code: [Select]
<?php
$artist 
= isset($_POST["artist"]) ? urlencode(stripcslashes($_POST["artist"])) : '';
$title = isset($_POST["title"]) ? urlencode(stripcslashes($_POST["title"])) : '';

if(empty(
$artist) ||empty($title))
    exit(
'No data to send');

$url "http://air.radiotime.com/Playing.ashx?partnerId=<id>&partnerKey=<key>&id=<stationid>&title=".$title."&artist=".$artist;

file_get_contents($url);
?>

Don't forget to replace <id>, <key> and <stationid> with actual values given by TuneIn.

Thanks for making the code a little cleaner. I wrote it really quick as an "example".  But as you pointed out, it's not meant to be manually called, it's for the web exporter that sends the parameters.
Radio DJ 1.7.5 Update with MariaDB 10

Re: TuneIn API Integration
« Reply #19 on: July 30, 2014, 09:51:30 PM »
You're welcome.
For me receiving the API keys took almost three weeks, but it might have been because had I sent my request on December 21st, right before holidays. I received the keys on January 9th.
It seems kinda awkward that somebody on their end has to generate the keys and send them by email instead of allowing broadcasters to register and generate the keys. Most other API services I've used (Twitter, Facebook, Google, etc.) generate keys automatically.

Hi Andy,
yesterday i receive my API key's and put them in the string on the right places, but it seems not to work, TuneIn says on there site Information does not update on the TuneIn.com site in realtime. Changes to station information can take up to a day to appear, well it's now more than a day, but no playing information so far.
Is there a way to check off it's working?
Or is there something wrong with the webexport settings, your php file name is TuneIn API.php and is the map TuneIn, or have i remove the password and let it blank?
Greetings Nico.


[attachment deleted by admin]

AndyDeGroo

Re: TuneIn API Integration
« Reply #20 on: July 31, 2014, 07:57:42 AM »
First, is your web server really listening on port 8080?
Second, check that have you inserted your API keys correctly?

Lets see what you get if you add another script for testing:
Code: [Select]
<?php
header
('Content-Type: text/plain');

$artist = isset($_REQUEST["artist"]) ? urlencode(stripcslashes($_POST["artist"])) : '';
$title = isset($_REQUEST["title"]) ? urlencode(stripcslashes($_POST["title"])) : '';

if(empty(
$artist) ||empty($title))
    exit(
'No data to send');

$url "http://air.radiotime.com/Playing.ashx?partnerId=<id>&partnerKey=<key>&id=<stationid>&title=".$title."&artist=".$artist;

$response file_get_contents($url);
echo 
$response;
?>

Place it on your server as tunein-test.php, replace TuneIn values in $url and open http://localhost:8080/TuneIn/tunein-test.php?artist=Test&title=Test in your browser.



Re: TuneIn API Integration
« Reply #21 on: July 31, 2014, 10:13:36 AM »
Andy,

This is what happening (see attachments), what do you mean with "First, is your web server really listening on port 8080" there's already a script running who reads the nowplaying.txt playlist and make php to html and a upload ftp to my site, it's running ok.
http://members.ziggo.nl/nchuijg/page1.htm
And the script from Marius from here http://www.radiodj.ro/community/index.php?topic=3440.0 was working ok as well.

What could be wrong?

Nico.

[attachment deleted by admin]

AndyDeGroo

Re: TuneIn API Integration
« Reply #22 on: July 31, 2014, 04:41:38 PM »
Let me repeat myself (with emphasis):
Quote
Place it on your server as tunein-test.php, replace TuneIn values in $url and open http://localhost:8080/TuneIn/tunein-test.php?artist=Test&title=Test in your browser.

Re: TuneIn API Integration
« Reply #23 on: July 31, 2014, 05:30:25 PM »
Let me repeat myself (with emphasis):
Andy,

This is what the browser tells me, like the txt file in the previous post.

Nico.

[attachment deleted by admin]

Offline HMC

  • ***
  • 181
Re: TuneIn API Integration
« Reply #24 on: August 01, 2014, 04:49:46 AM »
Andy,

This is what the browser tells me, like the txt file in the previous post.

Nico.

Something seems messed up on your localhost because it's not even parsing the html. You shouldn't see html tags.

Also if you are testing it in the browser it's going to be empty because you are checking the $_POST variable. You should use $_GET.

Code: [Select]
<?php
header
('Content-Type: text/plain');

$artist = isset($_GET["artist"]) ? urlencode(stripcslashes($_GET["artist"])) : '';
$title = isset($_GET["title"]) ? urlencode(stripcslashes($_GET["title"])) : '';

if(empty(
$artist) ||empty($title))
    exit(
'No data to send');

$url "http://air.radiotime.com/Playing.ashx?partnerId=<id>&partnerKey=<key>&id=<stationid>&title=".$title."&artist=".$artist;

$response file_get_contents($url);
echo 
$response;
?>


Also it looks like you are using an old version of Radiodj because newer versions allow you to choose your method. POST or GET. You should look into upgrading Radiodj also.  I believe the default is POST though even on that version. So the original script should work.
Radio DJ 1.7.5 Update with MariaDB 10

Re: TuneIn API Integration
« Reply #25 on: August 01, 2014, 10:27:27 PM »
I think i found the problem, in the field custom data i set the string "artist=$artist$&title=$title$" but i think the webexporter do not generate artist and title.
I try it with the php script from Marius.
<?php

If ((isset($_POST["xpwd"])) && (isset($_POST["title"]))) {
   $xpwd= stripcslashes($_POST["xpwd"]);
   if ($xpwd== 'changeme') {
      $data = stripcslashes($_POST["title"]);

      $Handle = fopen("data.txt", 'w');
      fwrite($Handle, $data);
      fclose($Handle);
   }
} Else {
   echo "Go away!";
}

?>
When the custom data field is empty it generate in the data.txt file nowplaying information set by options, when i change in "artist=$artist$&title=$title$" than it generate nothing in the data.txt file, so i think this also happening with the TuneIn API script.
What could be the problem? is that string right?
From this topic; http://www.radiodj.ro/community/index.php?topic=3440.0
Has anyone got a clue?

Nico.

AndyDeGroo

Re: TuneIn API Integration
« Reply #26 on: August 01, 2014, 10:48:15 PM »
Did you try what HMC suggested? I made a mistake in the script I posted and he corrected it.
If custom data field doesn't give results, try to leave it empty. Artist and title will still be sent to server.

Something seems messed up on your localhost because it's not even parsing the html. You shouldn't see html tags.
That is because of Content-type: text/plain header. I added that on purpose, to see what response TuneIn returns.

Try this in tunein-test.php and again, add your API details and open it in your browser to see what goes wrong:
Code: [Select]
<?php
header
('Content-Type: text/plain');

$artist = isset($_REQUEST["artist"]) ? urlencode(stripcslashes($_REQUEST["artist"])) : '';
$title = isset($_REQUEST["title"]) ? urlencode(stripcslashes($_REQUEST["title"])) : '';

// Save data for troubleshooting
file_put_contents'data.txt'print_r($_REQUESTtrue) );

if(empty(
$artist) ||empty($title))
    exit(
'No data to send');

$url "http://air.radiotime.com/Playing.ashx?partnerId=<id>&partnerKey=<key>&id=<stationid>&title=".$title."&artist=".$artist;

$response file_get_contents($url);
echo 
$response;
?>
This will also save all received parameters to data.txt.

Re: TuneIn API Integration
« Reply #27 on: August 02, 2014, 09:36:33 AM »
Hi Andy,
See for the results the attachment, and the data.txt shows
Array
(
    [xpwd] => Coen6210
    [title] => Hurricane Smith - Oh Babe What Would You Say [1972]
)
I understand that there is something wrong with HTTP request in the USB server, is there a solution for?
Nico.

[attachment deleted by admin]

AndyDeGroo

Re: TuneIn API Integration
« Reply #28 on: August 02, 2014, 11:30:33 AM »
No, there is nothing wrong with HTTP request. Don't jump to conclusion if you don't know what you're talking about.
You get server error 500 from TunIn API, because you have replaced wrong bits of the url. You should have replaced whole "<id>", "<key>" and "<stationid>" with your values.

Your data.txt contains only combined title. You should try to use custom data field in RDJ and see what gets saved in data.txt. If custom data doesn't provide artist and title (it should), you'll have to parse artist from combined title.

To make script a bit more foolproof, here it is with API keys moved to the top:
Code: [Select]
<?php
// TuneIn API settings
$StationID "s######";         // TuneIn station ID
$PartnerID "########";     // TuneIn partner ID
$PartnerKey "_########"// TuneIn partner key

$artist = isset($_REQUEST["artist"]) ? urlencode(stripcslashes($_REQUEST["artist"])) : '';
$title = isset($_REQUEST["title"]) ? urlencode(stripcslashes($_REQUEST["title"])) : '';

// Save data for troubleshooting
file_put_contents'data.txt'print_r($_REQUESTtrue) );

if(empty(
$artist) ||empty($title))
    exit(
'No data to send');

$url "http://air.radiotime.com/Playing.ashx?partnerId={$PartnerID}&partnerKey={$PartnerKey}&id={$StationID}&title={$title}&artist={$artist}";

echo 
file_get_contents($url);
?>



Offline Marius

  • *****
  • 5572
    • Radio DJ
Re: TuneIn API Integration
« Reply #29 on: August 02, 2014, 11:47:06 AM »
OFF: I wonder how 10 lines of code need 2 pages and counting...  :D
DOWNLOADS PAGE

HOW TO FIX RADIODJ DATABASE
----------------
Please don't PM me for support requests. Use the forums instead.