Forums » General Discussion Search

EMI Sandbox "access" function example or close? New Reply

Author Post
Posts: 5
Registered: Nov 25, 2011

I'd like to download the audio track for some of the selection in the emi_open_collection. I think I understand how to generate the URL except for the signature and maybe the id. Ideally, I'd like to do everything without leaving the sandbox. For example, I've collected this information from the sandbox regarding one particular Blondie song:

Dreaming,Essential,emi_open_collection/EMIDD1337110.mp3,843be8c5a232a7fdd4263e107d38291c,audio,open_collection

Now I'd like to listen to it to see if it is suitable for my game. So I think I want to put together a URL that looks something like this:

NSString* req = [NSString stringWithFormat:@"http://developer.echonest.com/api/v4/sandbox/access?api_key=%@&sandbox=%@&id=%@&oauth_consumer_key=%@&oauth_nonce=%@&oauth_timestamp=%@&oauth_signature_method=HMAC-SHA1&oauth_signature=%@", api_key, oauth_consumer_key, oauth_nonce, oauth_timestamp, sandbox, asset, oauth_signature];

I know what most of the parameters need to be, but I need to come up with oath_signature. Your documentation says this is kind of difficult and suggests using libraries, but when I look at Echonest Framework, Jen, and Pyechonest, I don't really see anything about HMAC-SHA1 encoding unless I am perhaps skipping over it. Of course, it would be ideal to have some function that I could include in an Objective-C program if possible.

I looked at the OAuth site suggested and even the NetFlix site. There just seem to be so many steps, including sorting parameters and working with the "base URL" (not sure what that means), that my chances of getting it to work exactly right seem small, so, as you suggest, using an existing library function seems much more practical, even if I have to switch languages to do it.

If all that is done successfully, is it true that it then hands me a temporary URL where I can access the audio as an mp3 file?

I think some of the audio files in the sandboxes could be quite good for my game, but right now I just need to listen to them carefully to pick out what I'd like to use.

Thanks much, Bruce

Posts: 113
Registered: Sep 05, 2008

Hi Bruce, OAuth is slightly complicated to roll your own. On iOS we use the OAuthConsumer class-- http://code.google.com/p/oauthconsumer/

This code will return a signed URL that should work if you replace the endpointURL, CUSTOMER_KEY and CUSTOMER_SECRET parts.

NSURL *endpointURL = [[NSURL alloc] initWithString:@"http://endpoint_url"];
OAConsumer *consumer = [[OAConsumer alloc] initWithKey:CUSTOMER_KEY secret:CUSTOMER_SECRET];
// default signature provider is HMAC_SHA1
OAMutableURLRequest *o = [[OAMutableURLRequest alloc] initWithURL:endpointURL consumer:consumer token:nil realm:nil signatureProvider:nil]; 
[o prepare];
NSURL *ret = [NSURL URLWithString:[o headerlessURL]];
[endpointURL release];
return ret;
Posts: 5
Registered: Nov 25, 2011

Thanks. I saw two versions versions in the Google archives for Objective-C: objc and objc1. They both compile, but I don't see where the method "headerlessURL" is defined. Am I perhaps looking at the wrong version?

Bruce

Posts: 113
Registered: Sep 05, 2008

that was my addition, sorry... add this headerlessURL line here in OAMutableURLRequest.m

NSString                    *consumerSecret = [self URLEncodedString: consumer.secret];
NSString                    *tokenSecret = [self URLEncodedString: token.secret];   
signature = [signatureProvider signClearText:[self _signatureBaseString]
                                  withSecret:[NSString stringWithFormat:@"%@&%@", consumerSecret, tokenSecret]];

headerlessURL = [NSString stringWithFormat:@"%@&oauth_signature=%@", presignatureURLString, [self URLEncodedString:signature]];

and then synthesize headerlessURL and define it in the .h.

Posts: 113
Registered: Sep 05, 2008

Here's the whole .m file:

https://gist.github.com/1404888

Posts: 5
Registered: Nov 25, 2011

In the code above, I don't understand where presignatureURLString comes from. It is assigned a value, but only after that section of code.

I posted a screenshot of the sorts of reference problems I am having here: http://oi40.tinypic.com/358w9vq.jpg (Sorry the resolution is not better.)

I am wondering if I am trying to combine it with the wrong version of the OAConsumer library. I've found several versions to download, but none of them seem to match up properly to be able to use your code above or the file you mention at https://gist.github.com/1404888

Thanks, Bruce

Reply to this Thread

You must log in to post a reply.