[英]iOS Facebook get friends list
- (void)viewDidLoad
{
[super viewDidLoad];
m_allFriends = [[NSMutableArray alloc] init];
if ([[FBSession activeSession] isOpen])
{
if ([[[FBSession activeSession] permissions]indexOfObject:@"user_friends"] == NSNotFound)
{
[[FBSession activeSession] requestNewPublishPermissions:[NSArray arrayWithObject:@"user_friends"] defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session,NSError *error){
[self getFBFriendListFunc];
NSLog(@"1");
}];
}
else
{
[self getFBFriendListFunc];
NSLog(@"2");
}
}
else
{
[FBSession openActiveSessionWithPublishPermissions:[NSArray arrayWithObject:@"user_friends"]
defaultAudience:FBSessionDefaultAudienceOnlyMe
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
if (!error && status == FBSessionStateOpen) {
[self getFBFriendListFunc];
NSLog(@"3");
}else{
NSLog(@"error");
}
}];
}
}
-(void)getFBFriendListFunc
{
[FBRequestConnection startWithGraphPath:@"me/friends"
parameters:nil
HTTPMethod:@"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
NSLog(@"me/friends result=%@",result);
NSLog(@"me/friends error = %@", error.description);
NSArray *friendList = [result objectForKey:@"data"];
[m_allFriends addObjectsFromArray: friendList];
}];
}
I try to connect Facebook with their API, actually this code connect Facebook, Facebook ask me this application want to use your information than i confirmed. 我尝试用他们的API连接Facebook,实际上这段代码连接了Facebook,Facebook问我该应用程序是否想使用您确认的信息。 Last step, Facebook return again my application than this
getFBFriendListFunc
should be run but none of if/else work. 最后一步,Facebook再次返回我的应用程序,而不是应该运行此
getFBFriendListFunc
但if / else都不起作用。 Nothing display... 什么也没显示...
I get this codes on Facebook developer which code part wrong ? 我在Facebook开发人员上得到此代码,哪个代码部分出错? Any idea ?
任何想法 ? Thank you...
谢谢...
For inviting users you can use the following code after adding the facebook-sdk 为了邀请用户,您可以在添加facebook-sdk之后使用以下代码
[FBWebDialogs
presentRequestsDialogModallyWithSession:sharedFacebookHelper.session
message:@"Your invite message"
title:nil
parameters:nil
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(@"Error publishing story: %@", error.description);
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
// User canceled.
NSLog(@"User cancelled.");
} else {
// Handle the publish feed callback
}
}
}];
I add this function on AppDelegate.m
if this function does not exit login session never be work i hope this code help any one :) 如果此功能没有退出登录会话,我会在
AppDelegate.m
上添加此功能,我希望此代码对任何人都有用:)
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
BOOL wasHandled = [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];
return wasHandled;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.