Akshay
Akshay

Reputation: 227

how to get facebook friends public information.?

i've used below lines of code to get my friends list along with their ID.. by providing permissions such as "read_friendlists" , i've got to know that using a friend "ID" we can get public information of that person. i've used Graph API explorer , i've got successfully, how to get those data programtically? how to post "ID" to get response?? Please help me.

[[FBRequest requestForMyFriends] startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {

    NSArray *arrFrinds = [result objectForKey:@"data"];

    for (NSArray<FBGraphUser>*obj in arrFrinds)
    {
        //id, username and firstname

        NSLog(@"My Friend ->> id : %@ \n  Username %@ \n Firstname %@ ",obj.id,obj.username,obj.first_name);

    }
}];

Upvotes: 1

Views: 174

Answers (1)

Anil Varghese
Anil Varghese

Reputation: 42977

Instead of requestForMyFriends use like

-(NSArray *)getFacebookFriends
{
    NSArray *friends;

    FBRequestConnection *connection = [[FBRequestConnection alloc] init];

    connection.errorBehavior = FBRequestConnectionErrorBehaviorReconnectSession
    | FBRequestConnectionErrorBehaviorAlertUser
    | FBRequestConnectionErrorBehaviorRetry;


    FBRequest *request= [[FBRequest alloc] initWithSession:[FBSession activeSession]
                                                 graphPath:@"me/friends"
                                                parameters:[NSDictionary dictionaryWithObjectsAndKeys:
                                                            @"id,name,username,first_name,last_name,birthday", @"fields",
                                                            nil]
                                                HTTPMethod:nil];

    [connection  addRequest:request  completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {

        if (!error)
        {
            NSLog(@"Facebook Friends : %@",result);

        }
    }];
    [connection start];
    return friends;
}

Specify whatever data you want as parameters. And the access permission "read_friendlists" i not the actual one required here. Look at the figure for the right one

enter image description here

Upvotes: 2

Related Questions