objective-c - GTMOAuth 的 FatSecret REST KIT 问题

标签 objective-c ios rest oauth restkit

我正在尝试使用 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];
}

非常感谢!

最佳答案

这似乎是两个独立的 OAuth 1 库(OAuthConsumer 和 GTM OAuth)的随机混合,它们不打算一起使用。

关于objective-c - GTMOAuth 的 FatSecret REST KIT 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12553419/

相关文章:

iphone - 模拟 ScrollView 内的拖动

rest - ColdFusion 和 REST

ios - 您可以使用 Mapkit 引用 Apple map 中的地点吗?

iphone - 随机调用一个方法

java - Java 到 Objective-C 的 Socket 连接

javascript - Google 云端硬盘上传文件大小限制

带参数的REST GET动词

objective-c - 意外的应用程序支持路径

ios - 在 iOS 中调用插入行到 IndexPath 后由于某种原因不保存数据

ios - 通过使用新数据以编程方式向左滑动来创建 View Controller