面向移动的Facebook请求对话 - 过滤用户

时间:2012-09-11 12:58:54

标签: ios facebook dialog request

我正在移动应用中使用请求对话框。读 https://developers.facebook.com/docs/reference/dialogs/requests/ 我发现了

  

注意:在移动设备对话框中禁用过滤器选项,不会影响对话框中显示的用户组。

不幸的是,我只需要在一个对话框中显示已安装app的朋友,并在另一个对话框中休息。在使用FB请求对话框时,有没有合理的方法来过滤这样的用户?

1 个答案:

答案 0 :(得分:1)

您可以查看与SDK一起打包的Hackbook示例应用程序,向您展示如何执行此操作,但实质上您必须创建一个API调用来获取,比如安装了应用程序的用户并将其传递给参数称为“建议”。

- (void)sendRequest:(NSArray *) targeted {
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               @"It's your turn, quit slacking.",  @"message",
                               nil];

    // Filter and only show targeted friends
    if (targeted != nil && [targeted count] > 0) {
        NSString *selectIDsStr = [targeted componentsJoinedByString:@","];
        [params setObject:selectIDsStr forKey:@"suggestions"];
    }

    [self.facebook dialog:@"apprequests"
                  andParams:params
                andDelegate:self];
}


- (void) sendToAppUsers {
    FBRequest *appUsersRequest = [[FBRequest alloc]
                                  initWithSession:FBSession.activeSession
                                  restMethod:@"friends.getAppUsers"
                                  parameters:nil
                                  HTTPMethod:@"GET"];
    FBRequestConnection *appUsersConnection = [[FBRequestConnection alloc] init];
    [appUsersConnection
     addRequest:appUsersRequest
     completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
         // Process the results
         NSMutableArray *friendsWithApp = [[NSMutableArray alloc] init];
         // Many results
         if ([result isKindOfClass:[NSArray class]]) {
             [friendsWithApp addObjectsFromArray:result];
         } else if ([result isKindOfClass:[NSDecimalNumber class]]) {
             [friendsWithApp addObject: [result stringValue]];
         }
         // User has friends that pass this filter
         if ([friendsWithApp count] > 0) {
             [self sendRequest:friendsWithApp];
         }
    }];
    [appUsersConnection start];
}