RadioDJ - Free Radio Automation Software Forum

TuneIn API Integration

Offline HMC

  • ***
  • 181
Re: TuneIn API Integration
« Reply #30 on: August 02, 2014, 12:36:54 PM »
OFF: I wonder how 10 lines of code need 2 pages and counting...  :D

Right? LOL

It really helps to learn basic PHP or customizing the site or what not will be difficult.

That is because of Content-type: text/plain header. I added that on purpose, to see what response TuneIn returns.


Yes duh I didn't pay attention to that for some reason.
Radio DJ 1.7.5 Update with MariaDB 10

Re: TuneIn API Integration
« Reply #31 on: August 02, 2014, 06:03:48 PM »
Code: [Select]
[quote author=AndyDeGroo link=topic=5506.msg33030#msg33030 date=1406971833]
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.
[/quote]

Andy,
First, there is nothing wrong with the id's and key from tunein, i copy/past them from the tunein e-mail, and checked them more then twice.
I find out that, the password in combination with a string in the custom data field in webexport, give's no artist and title information.
I let it blank, and with your new script now, it generate artist and title information in data.text.
I hope it works now, i have to wait a day or so to see of tunein wil update.
It could be that tunein sends me a wrong id and key.
Andy for now thank you so match, also HMC and Marius, and your moral support! and remember we are on page 3 of this subject, more to come?

Greetings Nico.

AndyDeGroo

Re: TuneIn API Integration
« Reply #32 on: August 02, 2014, 06:31:43 PM »
First, there is nothing wrong with the id's and key from tunein, i copy/past them from the tunein e-mail, and checked them more then twice.
No, I didn't mean that your keys were wrong. It wasn't working because you had left "<" and ">" in the url.

To put it bluntly;
This was wrong:
Code: [Select]
http://air.radiotime.com/Playing.ashx?partnerId=<CXXXXXYi>&partnerKey=<_aXXXXhKNopL>&id=<s209409>

This is correct:
Code: [Select]
http://air.radiotime.com/Playing.ashx?partnerId=CXXXXXYi&partnerKey=_aXXXXhKNopL&id=s209409

Please pay more attention to instructions and try to understand what you are doing. I've learned many things by trial and error and you should too.

Re: TuneIn API Integration
« Reply #33 on: August 05, 2014, 09:59:33 PM »
Andy,

I will let you know that the script is perfectly running, only when to many uploads in a short time go to tunein it blocks the gathering i think (time out) by two or more short items.
You have to consider that i dealing with RadioDJ just over two moths, and a shorter time with a php server, so there is a lot to learn, but for me its very abstract al those combination of chars in php.

Thank for your support once again, Nico.

Re: TuneIn API Integration
« Reply #34 on: September 03, 2014, 07:38:36 PM »
Please.  where i get partner ID  and Partnerkey?

Re: TuneIn API Integration
« Reply #35 on: September 04, 2014, 12:20:14 AM »
You have to contact TuneIn directly. Tell them you are using RadioDJ as your primary automation transmission.

Re: TuneIn API Integration
« Reply #36 on: September 04, 2014, 02:37:45 AM »
Thanks Packzap

Re: TuneIn API Integration
« Reply #37 on: September 06, 2014, 02:52:26 PM »
Hy Guys.   Please help me. TUNEIN API doesnt work.   I did it like MariusĀ“s post in NOW PLAYING INFO.  I have PartnerId , key, stationid.
I eliminate "<>".  Whats wrong?     

Radiodj   1.7.3.0

Offline TORPEDA

  • *
  • 13
  • www.boomboom.fm/
    • BOOMBOOM FM
Re: TuneIn API Integration
« Reply #38 on: September 28, 2014, 09:15:58 PM »
Farinha,
I've got two stations running on RadioDJ and both are feeling fine with TuneIn API. Please, check again if you did everything as it shown on Marius's post. Eliminate "<>". Set method as GET and check ENABLE. It could take some time for Api to start working. A could of hours at least. Good luck!
Boomboom FM

http://www.boomboom.fm

Re: TuneIn API Integration
« Reply #39 on: October 08, 2014, 11:58:10 PM »
I'm trying to send my TuneIn data only if the track type is '0'.  I don't knwo how to do PHP, can someone tell me where I'm going wrong (I've currently got a mash of a couple of other peoples scripts and it doesn't work properly)?

I'd also like to send the 'commercial=true' flag to TuneIn when the track type is anything other than '0'.  Can anyone help?

This is what I have so far (the data.txt file works just fine, everything after that fails).

I should point out that I replace the key, partner and station IDs with mine when using the script.

Thanks.

Code: [Select]
<?php
If ((isset($_POST["xpwd"])) && (isset($_POST["title"]))) {
$xpwdstripcslashes($_POST["xpwd"]);
if ($xpwd== 'mypasswordishere') {
$data .= stripcslashes($_POST["artist"]);
$data .= " - ";
$data .= stripcslashes($_POST["title"]);
$data .= " - ";
$data .= stripcslashes($_POST["track-type"]);
$Handle fopen("data.txt"'a');
fwrite($Handle$data."\n");
fclose($Handle);
        if (
track-type== '0')
                
$url "http://air.radiotime.com/Playing.ashx?partnerId=<id>&partnerKey=<key>&id=<stationid>&title=".$title."&artist=".$artist;
}
} Else {
echo "Access Denied";
}
?>

AndyDeGroo

Re: TuneIn API Integration
« Reply #40 on: October 09, 2014, 12:53:53 AM »
Did you run AutoUpdate.exe to get latest files after this post by Marius? Marius has fixed the $track-type$ issue I reported after releasing version 1.7.4.

You didn't mention what you have in your custom data field. Did you add "&track-type=$track-type$"? Are you actually sending the xpwd parameter? Note that if you type anything in "Custom Data", the password filed is ignored and you have to add xpwd=Pa$$w00rd to custom data.
Your script just creates the url and does nothing to make actual request. Where do you get title and artist variables?

Ok, your script wouldn't work anyway...

Here is a script that should do what you want:
Code: [Select]
<?php
define
('RDJ_PASSWORD''type your web export password here'); // RadioDJ Web Export password
$partnerId "XXXXX"// TuneIn API partner ID
$partnerKey "XXXXX"// TuneIn API partner key
$stationId "XXXXX"// TuneIn API station ID

ini_set('error_log''php_error.log');
ini_set('log_errors''on');
error_reporting(E_ERROR E_WARNING E_PARSE);

file_put_contents('data.txt'print_r($_POSTtrue)); // comment out this line after debugging

if ( isset($_POST["xpwd"]) && stripcslashes($_POST["xpwd"]) == RDJ_PASSWORD && isset($_POST["title"]) ) {    
    
$artisturlencode(stripcslashes($_POST["artist"]));
    
$title urlencode(stripcslashes($_POST["title"]));

    
$track_type = isset($_POST['track-type'])? (int)$_POST['track-type'] : -1;
    
$commercial = ($track_type === 0) ? 'false' 'true'// Check if track-type is exactly 0 (for Song) and set commercial flag accordingly

    
$url "http://air.radiotime.com/Playing.ashx?partnerId=$partnerId&partnerKey=$partnerKey&id=$stationId&title=".$title."&artist=".$artist."&commercial=$commercial";
    
$response file_get_contents($url);
    echo 
$response;

    
//file_put_contents('last_response.txt', date('[Y-m-d H:i:s]')."\n".$response); // for debugging

} else {
    echo 
"Access Denied";
}
?>


Just fill in the variables and RDJ_PASSWORD define at the top and it should work. I say "should" because I didn't test it.
This script assumes that your custom data contains following string:
Code: [Select]
xpwd=Pa$$w00rd&title=$title$&artist=$artist$&track-type=$track-type$

Please note that track-type variable must be provided and it must be a number or it will send everything as commercial=true.
« Last Edit: October 09, 2014, 01:45:07 AM by AndyDeGroo »

Re: TuneIn API Integration
« Reply #41 on: October 09, 2014, 08:47:46 AM »
That's amazing. Thank you.  I'll test it today.
Oh, and I am updated to 1.7.5 :)

Re: TuneIn API Integration
« Reply #42 on: October 09, 2014, 02:31:33 PM »
I've had it running this morning and I got a PHP error to start with:
Code: [Select]
[09-Oct-2014 12:28:57 UTC] PHP Warning:  file_get_contents(): http:// wrapper is disabled in the server configuration by allow_url_fopen=0 in tunein.php on line 21
[09-Oct-2014 12:28:57 UTC] PHP Warning:  file_get_contents(http://air.radiotime.com/Playing.ashx?partnerId=xxxxxxxx&amp;partnerKey=xxxxxxxx&amp;id=sxxxxxx&amp;title=If+It+Makes+You+Happy&amp;artist=Sheryl+Crow&amp;commercial=false): failed to open stream: no suitable wrapper could be found in tunein.php on line 21
I commented out the response section but I don't know if it is working or not!  My now playing info hasn't started appearing on TuneIn yet (we're here: http://tunein.com/radio/Beyond-Radio-s195739)!  No PHP errors though.

I'm not sure my partner key is being sent properly as it is missing some characters in the PHP error log and it contains a '$'.

I ended up using:
Code: [Select]
<?php
define
('RDJ_PASSWORD''password'); // RadioDJ Web Export password
$partnerId "xxxxxx"// TuneIn API partner ID
$partnerKey "xxxxxxxxxxxx"// TuneIn API partner key
$stationId "sxxxxxx"// TuneIn API station ID

ini_set('error_log''php_error.log');
ini_set('log_errors''on');
error_reporting(E_ERROR E_WARNING E_PARSE);

file_put_contents('data.txt'print_r($_POSTtrue)); // comment out this line after debugging

if ( isset($_POST["xpwd"]) && stripcslashes($_POST["xpwd"]) == RDJ_PASSWORD && isset($_POST["title"]) ) {    
    
$artisturlencode(stripcslashes($_POST["artist"]));
    
$title urlencode(stripcslashes($_POST["title"]));

    
$track_type = isset($_POST['track-type'])? (int)$_POST['track-type'] : -1;
    
$commercial = ($track_type === 0) ? 'false' 'true'// Check if track-type is exactly 0 (for Song) and set commercial flag accordingly

    
$url "http://air.radiotime.com/Playing.ashx?partnerId=$partnerId&partnerKey=$partnerKey&id=$stationId&title=".$title."&artist=".$artist."&commercial=$commercial";
/*  $response = file_get_contents($url);
    echo $response;

    //file_put_contents('last_response.txt', date('[Y-m-d H:i:s]')."\n".$response); // for debugging */

} else {
    echo 
"Access Denied";
}
?>

« Last Edit: October 09, 2014, 02:42:33 PM by Chrispy »

AndyDeGroo

Re: TuneIn API Integration
« Reply #43 on: October 09, 2014, 03:08:47 PM »
You've commented out the part which does the actual sending, hence nothing is being sent. The issue is as stated in the first error: "http:// wrapper is disabled in the server configuration by allow_url_fopen=0".

There are two options:
Easiest: If you control the server, enable allow_url_fopen=on or ask if your hosting provider can do it for you.
Harder: Rewrite the script to use curl, which I've already done for you below...

Here I've added a function to use curl when allow_url_fopen is disabled:
Code: [Select]
<?php
define
('RDJ_PASSWORD''type your web export password here'); // RadioDJ Web Export password
$partnerId "XXXXX"// TuneIn API partner ID
$partnerKey "XXXXX"// TuneIn API partner key
$stationId "XXXXX"// TuneIn API station ID

//file_put_contents('data.txt', print_r($_POST, true)); // Uncomment this line for debugging

function http_request($url) {
    
$response null;
    if( 
ini_get('allow_url_fopen') ) {
        
$response file_get_contents($url);
    } elseif(
function_exists('curl_init')) {
        
$curl curl_init($url);
        
curl_setopt($curlCURLOPT_RETURNTRANSFER1);
        
$response curl_exec($curl);
        
curl_close($curl);
    } else {
        
trigger_error("Cannot fetch resource because allow_url_fopen is disabled and cURL is not available"E_USER_ERROR);
    }
    return 
$response;
}

if ( isset(
$_POST["xpwd"]) && stripcslashes($_POST["xpwd"]) == RDJ_PASSWORD && isset($_POST["title"]) ) {   
    
$artiststripcslashes($_POST["artist"]);
    
$title stripcslashes($_POST["title"]);

    
$track_type = isset($_POST['track-type'])? (int)$_POST['track-type'] : -1;
    
$commercial = ($track_type === 0) ? 'false' 'true'// Check if track-type is exactlt 0 (for Song) and set commercial flag accordingly
    
$url "http://air.radiotime.com/Playing.ashx?partnerId=$partnerId&partnerKey=$partnerKey&id=$stationId&title=".$title."&artist=".$artist."&commercial=$commercial";
    
$response http_request($url);
    echo 
$response;

    
//file_put_contents('last_response.txt', date('[Y-m-d H:i:s]')."\n".$response); // for debugging

} else {
    echo 
"Access Denied";
}
?>

The script will fail and trigger an error if allow_url_fopen=0 and if PHP cURL extension is not enabled. If cURL is not available on your web server and you are paying for hosting services, you should consider changing your provider.

Obligatory note: Script was not tested and might fail miserably. Although I try my best to write working scripts without testing.

Re: TuneIn API Integration
« Reply #44 on: October 09, 2014, 04:26:44 PM »
Brilliant. :)

The return from 'last_response.txt' is:
Code: [Select]
[2014-10-09 14:22:05]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">

<HTML><HEAD><TITLE>Bad Request</TITLE>

<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>

<BODY><h2>Bad Request</h2>

<hr><p>HTTP Error 400. The request is badly formed.</p>

</BODY></HTML>


I still suspect that my partner key isn't being sent correctly as it contains a '$' sign.