Beatport API V3 working example in PHP

1,509 views
Skip to first unread message

Tim Brandwijk

unread,
Nov 22, 2013, 4:25:47 PM11/22/13
to beatpo...@googlegroups.com
Here's my code (PHP) to connect to version 3 of the API. I use the OAuth PECL extension for PHP to do the requests. The script does the user login part in the background.

I also use another tiny PHP script as oauth_callback to catch the verifier string after the user logs in. It's shared below and in the comments of the script.

What you need:
- OAuth PECL extension for PHP: http://pecl.php.net/package/oauth
- Consumer key and consumer secret provided by Beatport
- A normal Beatport user login/password

So, how it works:
1. It gets a request token using the consumer key/secret
2. Sets the request token/secret to log the user in
3. Logs the user in, and catches the verifier string (using the callback script)
4. Uses this verifier string to get the Access Token
5. Sets Access Token for all further API requests

Hope it helps someone out!
beatport_api_example_php.txt
beatport_callback_php.txt

Adau

unread,
Nov 23, 2013, 7:24:44 AM11/23/13
to beatpo...@googlegroups.com
Hi Tim,

Thank you very much for all this job, it helps me a lot and works perfectly fine!

Kai Hotz

unread,
Nov 23, 2013, 8:04:32 PM11/23/13
to beatpo...@googlegroups.com
Hi Tim

I Get The following error

Received OAuth Request token: XXXXXXX Received OAuth Request token secret: XXXXXXX
Fatal error: Uncaught exception 'OAuthException' with message 'Invalid auth/bad request (got a 401, expected HTTP/1.1 20X or a redirect)' in XXXXXX:112 Stack trace: #0 XXXXX: OAuth->getAccessToken('https://oauth-a...', '', '') #1 {main} thrown in XXXX

The line 112 is :  

$get_access_token = $oauth->getAccessToken($acc_url, "", $beatport_response->oauth_verifier);
if(!empty($get_access_token)) {
    print_r($get_access_token);
} else {
    print "Failed fetching access token, response was: " . $oauth->getLastResponse();
    exit();
}




Christian Kolloch

unread,
Nov 28, 2013, 5:53:35 AM11/28/13
to beatpo...@googlegroups.com
HI,


i' ve not the chance to install a PECL EXTENSION OAuth on our server,
so i use a PEAR PACKAGE : HTTP_OAUTH >> now, i can receive data from beatport api v3.
I've attached the file to this post.

but... how can I get the TOPTEN of an label-id? charts?

Releases:
https://oauth-api.beatport.com/catalog/3/releases?facets=labelId:xyz

TopTen:
https://oauth-api.beatport.com/catalog/3/charts?facets=labelId:xyz


sry for my bad english ...
grz. Chris
beatport_http_oauth_php.txt

Kai Hotz

unread,
Nov 28, 2013, 11:38:34 AM11/28/13
to beatpo...@googlegroups.com
I have the same problem, i would like to know how to query for all the releases ofa dj by dj's Name.

Kai Hotz

unread,
Nov 28, 2013, 7:13:30 PM11/28/13
to beatpo...@googlegroups.com
Just figured it out, it's realy simple:

replace:
$request = $oauth->sendRequest('https://oauth-api.beatport.com/catalog/3/labels', array('id'=>'xyz'));

with

$request = $oauth->sendRequest('https://oauth-api.beatport.com/catalog/3/charts array('id'=>xyz', 'perPage'=>'150'));

where xyz is the lable id you are searching the charts for.

Now if you want to query by lableName 

use:

$request = $oauth->sendRequest('https://oauth-api.beatport.com/catalog/3/charts array('facets'=>lableName:xyz', 'perPage'=>'150'));

where xyz is the lableName you are looking for

Hope i could help you.


El jueves, 28 de noviembre de 2013 07:53:35 UTC-3, Christian Kolloch escribió:

Tim Brandwijk

unread,
Nov 30, 2013, 9:38:11 AM11/30/13
to beatpo...@googlegroups.com

I'm glad I could help someone! The script was sponsored by Proton Radio: http://www.protonradio.com/

Kai, it looked like the callback script did not return the right values, or any values at all. I assume you got this problem fixed?

Regarding facet queries: any other facets should be comma separated, like this:
 
$oauth->fetch('https://oauth-api.beatport.com/catalog/3/releases', array('facets' => 'labelId:12679,returnValues:tracks', 'sortBy' => 'releaseDate DESC', 'perPage' => '100'));

Hope this helps!


Op zondag 24 november 2013 02:04:32 UTC+1 schreef Kai Hotz:

tunisiano

unread,
Dec 13, 2013, 9:54:04 AM12/13/13
to beatpo...@googlegroups.com
Hello for All,

I have the some problem as Christian !
I try to connect our web site to beatport API but this require to install a new entension on the server "OAuth PECL extension".

My web hosting "1and1" don't allow me to install it and we can't have for the moment our dedicated server.
So I'am looking for another solution without modifing the server configuration.


Some one can help me please ?

Thank you by advance !

Federico Giust

unread,
Feb 7, 2014, 12:34:11 PM2/7/14
to beatpo...@googlegroups.com

Hi Tim,

Thanks for the script.

I installed OAuth on my server and got it to work.

I made some minor updates to it like logging the calls to a db and use some query string to generate the api call depending on that.
I'm using it to generate a JSON object for a wordpress plugin.

Feel free to have a look

Cheers,
Fede

Federico Giust

unread,
Feb 7, 2014, 12:36:57 PM2/7/14
to beatpo...@googlegroups.com
Is your site using WordPress? If so, you can try this plugin


Cheers,
Fede
Message has been deleted

Adam Stark

unread,
Apr 1, 2014, 2:06:42 AM4/1/14
to beatpo...@googlegroups.com
I seem to be having a problem with the CURL of this script throwing a Invalid Nonce / timestamp error.

On line 69 of beatport_api_example.php $beatport response is returning as 

Invalid timestamp/nonce combination

which then in turn throws this error:

Notice: Undefined property: stdClass::$oauth_verifier in C:\Users\astark\Desktop\charts\beatport\beatport_api_example.php on line 77

Fatal error: Uncaught exception 'OAuthException' with message 'Invalid auth/bad request (got a 401, expected HTTP/1.1 20X or a redirect)' in C:\Users\astark\Desktop\charts\beatport\beatport_api_example.php:77 Stack trace: #0 C:\Users\astark\Desktop\charts\beatport\beatport_api_example.php(77): OAuth->getAccessToken('https://oauth-a...', '', '') #1 {main} thrown in C:\Users\astark\Desktop\charts\beatport\beatport_api_example.php on line 77

Not 100% sure whats wrong here?
Message has been deleted

Francesco Asturaro

unread,
Apr 4, 2014, 4:57:06 AM4/4/14
to beatpo...@googlegroups.com
Hi can you help me?

i can develop some list of my label on beatport:  http://www.protonradio.com/label_releases.php

What should I do??

help me please! ;-) thanks

Moussa Clarke

unread,
Jun 23, 2015, 9:58:09 AM6/23/15
to beatpo...@googlegroups.com, timbra...@gmail.com
Just got my Beatport API keys, so I've used Tim, Federico and Christian's code to hack together a simple Beatport API class in PHP. It's working (kind of) so I've thrown it up on Github in case anyone wants to make use of it or improve/contribute to it.


Hope it's useful!
Reply all
Reply to author
Forward
0 new messages