使用FBConnect选择朋友,但FBSession的accessTokenData从不具有启动会话的用户的用户ID(在他们的登录演示中也不存在)。 FBFriendPickerViewController返回朋友用户的ID很好,但我没有看到任何关于当前用户的信息。是否可以从FB活动会话,accessTokenData或其他方式获取当前用户的Id?
修改 是否可以从此次通话中返回用户的ID?
[FBSession openActiveSessionWithReadPermissions:@[@"public_profile", @"user_friends"]
一步完成这一切会好得多。
答案 0 :(得分:0)
你必须要求" / me"得到一个' user_id'因为access_token属性是加密的,你无法通过这种方式访问它。
答案 1 :(得分:0)
这是我最终做的事情:
if (!FBSession.activeSession.isOpen) {
// if the session is closed, then we open it here, and establish a handler for state changes
[FBSession openActiveSessionWithReadPermissions:@[@"public_profile", @"user_friends"]
allowLoginUI:YES
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
if (error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
else if (session.isOpen) {
if ([session.declinedPermissions containsObject:@"user_friends"]) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"friends"
message:@"Must allow accessing friends"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
else {
[[FBRequest requestForMe] startWithCompletionHandler:
^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
else {
NSLog(@"name %@ id %@", user.first_name, user.objectID);
[[FBRequest requestForMyFriends] startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error) {
NSArray* friends = [result objectForKey:@"data"];
NSLog(@"Found: %i friends", friends.count);
for (NSDictionary<FBGraphUser>* friend in friends) {
NSLog(@"I have a friend named %@ with id %@", friend.name, friend.objectID);
}
}];
}
}];
}
}
}];