OK, I've got a little further, and now I'm getting the error:
<code>8</code>
<message>Invalid signature: oauth_signature
'kD86RV3czf0480AYds2YWDAPZyE='</message>
Here's my code:
NSString *nonce = [self nonce];
NSString *timestamp = [self timeStamp];
NSMutableArray *noramlizedParameters = [[NSMutableArray alloc]
init];
NSString *search_expression = @"search_expression=Rice Krispies";
[noramlizedParameters addObject:search_expression];
NSString *method = @"method=foods.search";
[noramlizedParameters addObject:method];
NSString *oauth_consumer_key = [NSString
stringWithFormat:@"oauth_consumer_key=%@", kConsumerKey];
[noramlizedParameters addObject:oauth_consumer_key];
NSString *oauth_nonce = [NSString stringWithFormat:@"oauth_nonce=
%@", nonce];
[noramlizedParameters addObject:oauth_nonce];
NSString *oauth_signature_method = @"oauth_signature_method=HMAC-
SHA1";
[noramlizedParameters addObject:oauth_signature_method];
NSString *oauth_timestamp = [NSString
stringWithFormat:@"oauth_timestamp=%@", timestamp];
[noramlizedParameters addObject:oauth_timestamp];
NSString *oauth_version = @"oauth_version=1.0";
[noramlizedParameters addObject:oauth_version];
NSArray *sortedArray;
sortedArray = [noramlizedParameters
sortedArrayUsingSelector:@selector(compare:)];
[noramlizedParameters removeAllObjects];
noramlizedParameters = [NSMutableArray
arrayWithArray:sortedArray];
NSString *percentEscapedString = (__bridge NSString
*)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
(__bridge CFStringRef)[noramlizedParameters
componentsJoinedByString:@"&"], NULL, CFSTR(":/?#[]@!$&’()*+,;="),
kCFStringEncodingUTF8);
NSString *percentEscapedURL = (__bridge NSString
*)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
(__bridge CFStringRef)@"
http://platform.fatsecret.com/rest/
server.api", NULL, CFSTR(":/?#[]@!$&’()*+,;="),
kCFStringEncodingUTF8);
NSString *signatureBaseString = [NSString stringWithFormat:@"POST&
%@&%@",percentEscapedURL , percentEscapedString];
NSLog(@"signatureBaseString = %@\n\n", signatureBaseString);
NSDictionary *parametersDictionary = [NSDictionary
dictionaryWithObjectsAndKeys:
@"Rice Krispies",
@"search_expression",
@"foods.search", @"method",
kConsumerKey,
@"oauth_consumer_key",
nonce, @"oauth_nonce",
@"HMAC-SHA1",
@"oauth_signature_method",
timestamp,
@"oauth_timestamp",
@"1.0", @"oauth_version",
[self
signature:signatureBaseString], @"oauth_signature",
nil];
NSLog(@"parametersDictionary = %@\n\n", parametersDictionary);
[AppDelegate httpPOSTWithRelativePath:@"rest/server.api"
parameters:parametersDictionary block:^(NSData *returnedXMLData)
{
//[returnedXMLData writeToFile:[AppDelegate
dataFilePath:@"XMLData.xml"] atomically:TRUE];
NSString *XMLString = [[NSString alloc]
initWithData:returnedXMLData encoding:NSUTF8StringEncoding];
NSLog(@"xmlString = %@\n\n", XMLString);
TBXML *tbxml = [TBXML tbxmlWithXMLString:XMLString];
if (tbxml.rootXMLElement)
{
//[self traverseElement:tbxml.rootXMLElement];
}
}];
My base string looks like this:
POST&http%3A%2F%
2Fplatform.fatsecret.com%2Frest%2Fserver.api&method
%3Dfoods.search%26oauth_consumer_key%XXXXXXXXXXXXXXXXXX%26oauth_nonce
%3DE16118C8-E0AE-4882-8B90-97928ECBDF2B%26oauth_signature_method
%3DHMAC-SHA1%26oauth_timestamp%3D1332331555%26oauth_version
%3D1.0%26search_expression%3DRice%20Krispies
As far as I can tell I've followed the signing instructions to the
letter, and I've checked my SHA1 hashing algorithm online and I get a
match. Can anyone help me get this working?
Many thanks,
Rob