通过应用程序发送Facebook请求

时间:2014-04-17 11:27:53

标签: ios objective-c facebook

我阅读了facebook文档并实现了我的代码,但请求没有发送。我无法在网站上看到请求通知。我可以在日志屏幕上看到请求ID。

这是我的代码部分: 我从developer.facebook.com

获取了这段代码
+ (NSDictionary*)parseURLParams:(NSString *)query {
NSArray *pairs = [query componentsSeparatedByString:@"&"];
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
for (NSString *pair in pairs) {
    NSArray *kv = [pair componentsSeparatedByString:@"="];
    NSString *val =
    [kv[1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    params[kv[0]] = val;
}
return params;
}

+(void) requestFriendMethod{

// Display the requests dialog
[FBWebDialogs
 presentRequestsDialogModallyWithSession:nil
 message:@"message"
 title:@"title"
 parameters:nil
 handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
     if (error) {
         // Error launching the dialog or sending the request.
         NSLog(@"Error sending request.");
     } else {
         if (result == FBWebDialogResultDialogNotCompleted) {
             // User clicked the "x" icon
             NSLog(@"User canceled request.");
         } else {
             // Handle the send request callback
             NSDictionary *urlParams = [AKFacebook parseURLParams:[resultURL query]];
             if (![urlParams valueForKey:@"request"]) {
                 // User clicked the Cancel button
                 NSLog(@"User canceled request.");
             } else {
                 // User clicked the Send button
                 NSString *requestID = [urlParams valueForKey:@"request"];
                 NSLog(@"Request ID: %@", requestID);
             }
         }
     }
 }];

}

我做错了什么?感谢您的回答和建议。

1 个答案:

答案 0 :(得分:0)

确保您的Facebook应用ID在开发者页面和xcode中的信息中相同,启用沙盒模式,并且必须在开发者页面中填写[在Facebook类别的应用下]的画布URL。

NSString *facebookID = @"Your friend facebook id";
    NSMutableDictionary* params =
    [NSMutableDictionary dictionaryWithObject:facebookID forKey:@"to"];

    NSString *message = @"SOME_MESSAGE";
    NSString *title = @"TITLE";

    [FBWebDialogs presentRequestsDialogModallyWithSession:nil
                  message:message
                title:title
                parameters:params handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
                        if (error)
                    {
                    // Case A: Error launching the dialog or sending request.
                        NSLog(@"Error sending request.");
                    }
                    else
                    {
                        if (result == FBWebDialogResultDialogNotCompleted)
                    {
                    // Case B: User clicked the "x" icon
                        NSLog(@"User canceled request.");
                    }
                    else
                    {
                        NSLog(@"Request Sent. %@", params);
                    }
        }}];