大家好,我至少在处理一个大问题,我已经实现了旧版本的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";
}
答案 0 :(得分:0)
下面我附上了FB登录&从Facebook获取详细信息。试试那个代码&进行比较。
- (IBAction)facebook_BtnTap:(id)sender {
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions:@[@"public_profile",@"email"]handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
{
if (error) {
NSLog(@"Process error");
} else if (result.isCancelled) {
NSLog(@"Cancelled");
} else {
if ([result.grantedPermissions containsObject:@"email"]) {
// Do work
[self GetUserDetails];
}
}
}];
}
-(void)GetUserDetails
{
BOOL LOGGING;
if (LOGGING) {
return;
}
LOGGING = YES;
// [super startLoader];
if ([FBSDKAccessToken currentAccessToken])
{
NSLog(@“Check Already login");
//[FBSession openActiveSessionWithAllowLoginUI: YES];
// [self back:nil];
// return;
}
NSMutableDictionary* parameters = [NSMutableDictionary dictionary];
[parameters setValue:@"id,name,email,first_name,last_name,birthday,picture.type(large),location,hometown,gender" forKey:@"fields"];
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:parameters]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSString* email = [result objectForKey:@"email"];
NSString* fname = [result objectForKey:@"first_name"];
NSString* lname = [result objectForKey:@"last_name"];
NSString* userName = [result objectForKey:@"name"];
NSString* gender = [result objectForKey:@"gender"];
NSDictionary* hometown=[result objectForKey:@"hometown"];
NSString* country = [hometown objectForKey:@"name"];
NSString* birthday=[result objectForKey:@"birthday"];
// NSArray* photo =[[result objectForKey:@"picture"]valueForKey:@"data"];
// NSDictionary* location = [result objectForKey:@"location"];
// NSString* city = [location valueForKey:@"name"];
// NSString* fbPhoto = [photo valueForKey:@"url"];
NSString* fid = [result objectForKey:@"id"];
}];
}