Facebook iOS presentRequestsDialogModallyWithSession to return selected friends

情到浓时终转凉″ 提交于 2019-12-08 19:10:52

问题


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?


回答1:


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 ;)




回答2:


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.



来源:https://stackoverflow.com/questions/22358156/facebook-ios-presentrequestsdialogmodallywithsession-to-return-selected-friends

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!