gpt4 book ai didi

ios - 如何使用 Facebook iOS SDK 4.0 获取包含用户名和 ID 的用户好友列表

转载 作者:行者123 更新时间:2023-11-29 10:31:41 25 4
gpt4 key购买 nike

我正在尝试获取用户的好友列表。我在 FacebookSDK 3.12 中实现的最后一个工作代码现在没有用了,因为 facebook 已经更改了所有类,甚至删除了旧类,下面是我的旧代码:

#pragma mark - Facebook Methods -
-(void)initiateFacebookSessionIfNot
{
if (FBSession.activeSession.isOpen)
{
[self getUserFriendsIds];
} else
{
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"user_birthday",@"friends_hometown",
@"friends_birthday",@"friends_location",
nil];
[FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status,NSError *error)
{
if (error) {
NSString *alertMessage, *alertTitle;

if (error.fberrorShouldNotifyUser) {
alertTitle = @"Something Went Wrong";
alertMessage = error.fberrorUserMessage;
} else if (error.fberrorCategory == FBErrorCategoryUserCancelled) {
NSLog(@"user cancelled login");
} else {
// For simplicity, this sample treats other errors blindly.
alertTitle = @"Unknown Error";
alertMessage = @"Error. Please try again later.";
NSLog(@"Unexpected error:%@", error);
}

if (alertMessage)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:alertTitle
message:error.fberrorUserMessage
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
} else if (FB_ISSESSIONOPENWITHSTATE(status)) {
[self getUserFriendsIds];
}
}];
}
}
-(void)getUserFriendsIds
{
FBRequest *friendRequest = [FBRequest requestForGraphPath:@"me/friends?fields=name,username"];
[ friendRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSMutableArray *fbFriendIDs;
NSMutableArray *fbFriendsName;
NSMutableArray *fbFriendsUserName;

NSMutableArray *data = [[NSMutableArray alloc]initWithArray:[result objectForKey:@"data"]];
[data enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if (!(NSDictionary*)obj[@"username"]) {

NSDictionary *newDictionary =@{@"id": (NSDictionary*)obj[@"id"],
@"name": (NSDictionary*)obj[@"name"],
@"username": @"0"
};
[data replaceObjectAtIndex:idx withObject:newDictionary];
}
}];

fbFriendsUserName = [[NSMutableArray alloc]initWithArray:[data valueForKeyPath:@"@unionOfObjects.username"]];
fbFriendsName = [[NSMutableArray alloc]initWithArray:[data valueForKeyPath:@"@unionOfObjects.name"]];
fbFriendIDs = [[NSMutableArray alloc]initWithArray:[data valueForKeyPath:@"@unionOfObjects.id"]];

NSDictionary *queryDictionary =
@{@"user_id": userObj.user_id,
@"friend_ids":[fbFriendIDs componentsJoinedByString:@","],
@"names":[fbFriendsName componentsJoinedByString:@","],
@"usernames":[fbFriendsUserName componentsJoinedByString:@","]
};

[[RequestHandler sharedClient] CheckFBFriendsWithDictionary:queryDictionary WithCompletionBlock:^(NSArray *TUNFriendsArray, NSArray *FBFriendsArray, NSString *errorMessage) {
if (!errorMessage) {

tunFriendsArray = [[NSMutableArray alloc]initWithArray:TUNFriendsArray];
// fbFriendsArray = [[NSMutableArray alloc]initWithArray:FBFriendsArray];

[_facebookTableView reloadData];
}
else{
[ApplicationUtilities ShowAlertViewWithTitle:APP_NAME Message:errorMessage];
}
}];
}];
[SVProgressHUD dismiss];
}

最佳答案

Facebook 在其新版本即 V2.0 中更改了很多实现,其中 Tag-gable Friends API , Invitable Friend API , Social Context API , Business Mapping APITagged Places API是新功能。他们还进行了许多权限更改以提高安全性从以下链接阅读更多信息

希望您能从上述链接中找到所需的实现更改。

关于ios - 如何使用 Facebook iOS SDK 4.0 获取包含用户名和 ID 的用户好友列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29342457/

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