gpt4 book ai didi

iphone - 如何在不打开FBFriendPickerViewController iOS的情况下获取好友列表

转载 作者:可可西里 更新时间:2023-11-01 05:41:38 25 4
gpt4 key购买 nike

我正在为 iOS 使用 Facebook sdk 3.2,
有各种适用于 iOS 的示例项目
但我的问题是如何在不打开 FBFriendPickerViewController 的情况下获取好友列表。
事实上,我想要我所有 friend 的 facebook id 和那里任何帮助将不胜感激。
提前致谢

最佳答案

试试这个:

获取好友列表使用

**[FBRequest requestForMyFriends];**

**FBRequest* friendsRequest = [FBRequest requestForMyFriends];**

[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,NSDictionary* result,NSError *error) {
NSArray* friends = [result objectForKey:@"data"]; ......

代码如下,但主线是

 **[FBRequest requestForMyFriends];**

-(void)sessionStateChanged:(FBSession *)session state:(FBSessionState)state error:(NSError *)error {
switch (state) {
case FBSessionStateOpen: {
if (self != nil) {
[[FBRequest requestForMe] startWithCompletionHandler: ^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (error) {
//error
}else{
FBRequest* friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,NSDictionary* result,NSError *error) {
NSArray* friends = [result objectForKey:@"data"];

for (int i = 0; i < [arrFacebookFriends count]; i++) {
UserShare *shareObj = [arrFacebookFriends objectAtIndex:i];
[shareObj release];
shareObj = nil;
}
[arrFacebookFriends removeAllObjects];

for (NSDictionary<FBGraphUser>* friend in friends) {
UserShare *shareObj = [[UserShare alloc] init];
shareObj.userName = friend.name;
shareObj.userFullName = friend.username;
shareObj.userId = [friend.id intValue];
NSLog(@"%@",friend.id);
shareObj.userPhotoUrl = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?", friend.id];
[arrFacebookFriends addObject:shareObj];
[shareObj release];
}
[self StopSpinner];
[tblFacebookFriends reloadData];
}];
}
}];
}
FBCacheDescriptor *cacheDescriptor = [FBFriendPickerViewController cacheDescriptor];
[cacheDescriptor prefetchAndCacheForSession:session];
}
break;
case FBSessionStateClosed: {
[self StopSpinner];
UIViewController *topViewController = [self.navigationController topViewController];
UIViewController *modalViewController = [topViewController modalViewController];
if (modalViewController != nil) {
[topViewController dismissViewControllerAnimated:YES completion:nil];
}
//[self.navigationController popToRootViewControllerAnimated:NO];

[FBSession.activeSession closeAndClearTokenInformation];

[self performSelector:@selector(showLoginView) withObject:nil afterDelay:0.5f];
}
break;
case FBSessionStateClosedLoginFailed: {
[self StopSpinner];
[self performSelector:@selector(showLoginView) withObject:nil afterDelay:0.5f];
}
break;
default:
break;
}

[[NSNotificationCenter defaultCenter] postNotificationName:SCSessionStateChangedNotificationFL object:session];

if (error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"Error: %@", [FacebookFriendsListViewController FBErrorCodeDescription:error.code]] message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
[alertView release];
}
}

关于iphone - 如何在不打开FBFriendPickerViewController iOS的情况下获取好友列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15709226/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com