简体   繁体   中英

Facebook iOS presentRequestsDialogModallyWithSession to return selected friends

I am developing an iOS app and I want to be able to send invitations to my app through facebook, which I managed to do using presentRequestsDialogModallyWithSession

But I also want my app to know to whom the invitations were sent.. Is that possible?

Yes it is absolutely possible. Here is the way to get the list of user's friends to whom the user has sent invitation.

In presentRequestsDialogModallyWithSession there must be a handler some thing like this:

handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {

you can get the result of response URL in resultURL variable. If you convert it to string by using this method

[resultURL parameterString]

you will get fbconnect URL, which is something like this: fbconnect://success?request=57985658213xxxx&to%5B0%5D=13xxxxxxx9&to%5B1%5D=1000000xxxxxxx3

here, first parameter after request= is "57985658213xxxx&to" which is request id, and remaining parameters separated by "&to%5B0%5D=" and "&to%5B1%5D=" are friends' facebook id. Here I have sent the invitation to two persons, here are they: 13xxxxxxx9, 1000000xxxxxxx3

Instead of all digits, I have placed xxxxxxx in the above ids because I don't want to show my friends' facebook id publicly here in stackoverflow ;)

To add to regeint's answer, after converting the returned URL to a string using

NSString* fbResponse = [resultURL absoluteString];

I iterate through the list of Facebook friends I sent to presentRequestsDialogModallyWithSession (in order) and created the following regular expression to extract the friend's Facebook ID from the URL string returned:

(?:to%5B0%5D\=)(\d+)

where 0 is the index of the item I want, in this example, the first one.

Note: While this works, I find this whole solution pretty fragile. It's sensitive to the response from the presentRequestsDialogModallyWithSession not changing at all. A better solution would probably be to forego the Objective-C class and make the graph call via an HTTP request, which would hopefully return JSON instead like it does in javascript -- much more robust.

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