Search code examples
objective-ciosfacebookfacebook-graph-apifacebook-ios-sdk

Passing a Facebook Places id, from placesPicker in iOS... to postParams for a feed publish


This has been driving me bananas! I'm trying to get my app to publish a message to the users facebook feed, and a checkin to a facebook Place after selecting a local place from the placesPicker in iOS.

I've pretty much got everything working in testing, meaning when I just hand type string values for all the postParams for the NSMutableDictionary, it posts perfectly. ex:

self.postParams =
    [[NSMutableDictionary alloc] initWithObjectsAndKeys:
     @"I am doing XYZ", @"message",
     @"123456abc",@"tags",
     @"123456xyz,@"place",
     nil];

The above postParams work perfectly when published to feed, it displays the message, then checks in to the "place" id and says you are with the userid in "tags". The problem is that I am really getting the Place id from the Facebook SDK's placePicker. I've got the picker setup and working perfectly, but I can not figure out how to replace the hardcoded @"123456xyz" with the id from the picked Place.

this is currently what I have in there now:

self.postParams =
        [[NSMutableDictionary alloc] initWithObjectsAndKeys:
         @"I am doing XYZ", @"message",
         @"123456abc",@"tags",
         self.selectedPlace.id,@"place",
         nil];

self.selectedplace.id does successfully contain the id of the Place, when i print it with debug/NSLog in console, it is holding the value accurately. but when i try to publish this after picking a place, I get "error: domain = com.facebook.sdk, code = 5"

Here is how self.selectedPlace is defined & synthesized:

@property (strong, nonatomic) NSObject<FBGraphPlace> *selectedPlace;

...

@synthesize selectedPlace = _selectedPlace;

...

[placePicker presentModallyFromViewController:self
                                     animated:YES
                                      handler:^(FBViewController *sender, BOOL donePressed) {
                                          if (donePressed) {
                                              self.selectedPlace = placePicker.selection;
                                          }
                                      }];

So, to sum my question: How can I successfully get this Place id that is stored in self.selectedPlace.id into the postParams dictionary, so that it can be successfully interpreted & published to the user's feed?

Also, I should warn everyone upfront... I am self taught and still learning, and although I can look at the code, understand what it does, and write it... I'm afraid I'm not great with the terminology & discussing/understanding some of the language... lol so it would help me a great deal if you keep that in mind in any answers or comments :) Thanks, and I'm looking forward to breaking out of my stackoverflow newb shell and becoming more apart of the community here.


Solution

  • Figured it out... rather than setting the post params collectively with initWithObjectsAndKeys, like this:

    self.postParams =
        [[NSMutableDictionary alloc] initWithObjectsAndKeys:
         @"I am doing XYZ", @"message",
         @"123456abc",@"tags",
         self.selectedPlace.id,@"place",
         nil];
    

    Just create separate dictionaries for each param you are passing and set each one to the final postParams with setValue: forKey:

    [fbPostParams setValue:self.selectedPlace.id forKey:@"place"];