我正在尝试使用 FatSecret Rest API 和 GTMOAuth,但我不知道出了什么问题。有没有经验的人可以告诉我我做错了什么?
我是 Objective-C 的新手,所以请耐心等待。
- (void)sendRequests4
{
NSString *consumerKey = @"my consumer key";
NSString *sharedSecret = @"my shared secret key";
RKClient *client = [RKClient sharedClient];
GTMOAuthAuthentication *auth = [[GTMOAuthAuthentication alloc]
initWithSignatureMethod:kGTMOAuthSignatureMethodHMAC_SHA1
consumerKey:client.OAuth1ConsumerKey
privateKey:client.OAuth1ConsumerSecret];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:client.baseURL];
auth.shouldUseParamsToAuthorize = YES;
[auth addAuthorizeTokenParamsToRequest:request];
[auth addAuthorizeTokenHeaderToRequest:request];
// Perform a simple HTTP GET and call me back with the results
NSMutableDictionary* params = [NSMutableDictionary dictionary];
[params setValue:consumerKey forKey:@"oauth_consumer_key"];
[params setValue:kGTMOAuthSignatureMethodHMAC_SHA1 forKey:@"oauth_signature_method"];
[params setValue:auth.timestamp forKey:@"oauth_timestamp"];
[params setValue:auth.nonce forKey:@"oauth_nonce"];
[params setValue:@"1.0" forKey:@"oauth_version"];
[params setValue:@"??????" forKey:@"oauth_signature"];
[params setValue:@"foods.get_most_eaten" forKey:@"method"];
[params setValue:@"??????" forKey:@"oauth_token"];
NSURL *url = [NSURL URLWithString:@"http://platform.fatsecret.com/rest/server.api"];
NSString *sigSecret = [NSString stringWithFormat:@"%@&", sharedSecret];
NSString *sig = [OAHMAC_SHA1SignatureProvider signature:params
AndURL:url
AndHTTPMethod:@"POST"
AndSignatureSecret:sigSecret];
NSString *encodedSignature = [sig urlEncodeUsingEncoding:NSUTF8StringEncoding];
[params setValue:encodedSignature forKey:@"oauth_signature"];
[client post:@"foods.get_most_eaten" params:params delegate:self];
}
非常感谢!