0

Facebook が統合されたアプリケーションを作成しています。友達リストなどを取得する Facebook を組み込みましたが、特定のユーザーのグループ リストを取得するのに問題があります。

4

2 に答える 2

0

独自のグループだけを取得する方法のより完全な例を次に示します。

// list the permissions you want
NSArray *permissions = [[NSArray alloc] initWithObjects:
                        @"user_groups",
                        nil];

// handle Facebook Login preliminaries...
if (!FBSession.activeSession.isOpen) {
    // if the session is closed, then we open it here, and establish a handler for state changes
    [FBSession openActiveSessionWithReadPermissions:permissions
                                       allowLoginUI:YES
                                  completionHandler:^(FBSession *session,
                                                         FBSessionState state,
                                                         NSError *error) {
        if (error) {
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
                                                                message:error.localizedDescription
                                                               delegate:nil
                                                      cancelButtonTitle:@"OK"
                                                      otherButtonTitles:nil];
            [alertView show];
        } else if (session.isOpen) {
            [self pickFriendsButtonClick:sender];
        }
    }];
    return;
}

// set the GRAPH API query
FBRequest* req = [FBRequest requestForGraphPath:@"/me/?fields=name,groups"];

// create pointer to a backend connection
FBRequestConnection* reqconn = [[FBRequestConnection alloc] init];

// attach request to connection
[reqconn addRequest:req completionHandler:^(FBRequestConnection *connection,
                                            id result,
                                            NSError *error){
    NSDictionary *resultDict = (NSDictionary<FBGraphUser> *) result;

    NSString *path;

    path = [resultDict objectForKey:@"group"];


    if (resultDict == nil)
    {
        // This means the dictionary does not contain anything
        NSLog (@"Don't know the path to the groups");
    }
    else
    {
        // Print out the data (including groups).

        for(NSString *key in [resultDict allKeys]) {
            NSLog(@"%@, %@",key, [resultDict objectForKey:key]);
        }
    }

}];

// actually invoke the request
[reqconn start];
于 2013-08-03T13:30:42.013 に答える