简体   繁体   中英

Can't access event name from Facebook graph api response iOS

I am calling the graph api to retrieve my user's events.And I get back an NSDictionary response. My problem is that I'm trying to access the names of the events but can't figure out the correct way of doing it. Can you please help me with this?

My response :

 events =     {
    data =         (
                    {
            id = 16245704637388667;
            name = "My event name";
            place =                 {
                id = 278379712223737;
                location =                     {
                    city = Beijing;
                    country = China;
                    latitude = "53.598408783333";
....

Mycode to retrieve the vent name:

 if ([result objectForKey:@"data"]){

                 NSArray *events = [result objectForKey:@"data"];
                 NSString *text=@"You don't have events!";
                 for (NSDictionary* myevent in events) {
                     NSString *myeventName = [myevent objectForKey:@"name"];
                      NSLog(@"%@",myeventName);
                 }

 }

Found a solution:

    [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me/events" parameters: @{@"fields": @"name"}]
         startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
             if (!error) {

             NSMutableArray* events = [result objectForKey:@"data"];

             events names = [events valueForKey:@"name"];

         }
     }];`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM