【发布时间】:2017-08-07 18:15:31
【问题描述】:
您好,至少对我来说,我正在处理一个大问题,我已经实现了旧版本的 Facebook SDK 我在我的应用中使用这个 SDK 有很多功能,更新到最新版本需要几天时间,我现在没有时间这样做,所以我想做的很简单,我只想接收参数 email、last_name 和 name 但 Facebook 只是返回我的名字和 id,所以你有什么想法或我做错了什么?提前致谢。
- (void)requestUserInfo{
// We will request the user's public picture and the user's birthday
// These are the permissions we need:
NSArray *permissionsNeeded = @[@"public_profile", @"email"];
// Request the permissions the user currently has
if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded)
{
// If there's one, just open the session silently, without showing the user the login UI
[FBSession openActiveSessionWithReadPermissions:@[@"public_profile", @"email"]
allowLoginUI:NO
completionHandler:^(FBSession *session, FBSessionState state, NSError *error)
{
NSLog(@"%@", session.accessTokenData.accessToken);
}];
}
[FBRequestConnection startWithGraphPath:@"me"
parameters:[NSDictionary dictionaryWithObject:@"id,email,name,last_name" forKey:@"fields"]
HTTPMethod:@"GET"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error){
// Parse the list of existing permissions and extract them for easier use
NSMutableArray *currentPermissions = [[NSMutableArray alloc] init];
NSArray *returnedPermissions = (NSArray *)[result data];
for (NSDictionary *perm in returnedPermissions) {
if ([[perm objectForKey:@"status"] isEqualToString:@"granted"]) {
[currentPermissions addObject:[perm objectForKey:@"permission"]];
}
}
//NSLog(@"Needed: %@", permissionsNeeded);
//NSLog(@"Current: %@", currentPermissions);
NSMutableArray *requestPermissions = [[NSMutableArray alloc] initWithArray:permissionsNeeded copyItems:YES];
[requestPermissions removeObjectsInArray:currentPermissions];
//NSLog(@"Asking: %@", requestPermissions);
// If we have permissions to request
if ([requestPermissions count] > 0){
// Ask for the missing permissions
[FBSession.activeSession
requestNewReadPermissions:requestPermissions
completionHandler:^(FBSession *session, NSError *error) {
if (!error) {
// Permission granted, we can request the user information
[self makeRequestForUserData];
} else {
// An error occurred, we need to handle the error
// Check out our error handling guide: https://developers.facebook.com/docs/ios/errors/
NSLog(@"error %@", error.description);
}
}];
} else {
// Permissions are present
// We can request the user information
[self makeRequestForUserData];
}
} else {
// An error occurred, we need to handle the error
// Check out our error handling guide: https://developers.facebook.com/docs/ios/errors/
NSLog(@"error %@", error.description);
}
}];
}
这是信息:
llega el objeto:{
id = 10210924411602727;
name = "Del Mar Sal";
}
【问题讨论】:
标签: ios objective-c facebook