iOS: user's full name for an ACAccountTypeIdentifierFacebook

女生的网名这么多〃 提交于 2019-12-08 20:25:31

What you're doing there with the valueForKey:@"properties" call is accessing a private property and it will get your app rejected by Apple.

If your project is an iOS 7 project, you can use a new property on the ACAccount class called userFullName. From ACAccount.h:

// For accounts that support it (currently only Facebook accounts), you can get the user's full name for display
// purposes without having to talk to the network.
@property (readonly, NS_NONATOMIC_IOSONLY) NSString *userFullName NS_AVAILABLE_IOS(7_0);

Alternatively, you can use the Graph API to query the current user using the Social framework:

SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                     requestMethod:SLRequestMethodGET
                                               URL:[NSURL URLWithString:@"https://graph.facebook.com/me"]
                                        parameters:nil];
request.account = account; // This is the account from your code
[request performRequestWithHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
    if (error == nil && ((NSHTTPURLResponse *)response).statusCode == 200) {
        NSError *deserializationError;
        NSDictionary *userData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&deserializationError];

        if (userData != nil && deserializationError == nil) {
            NSString *fullName = userData[@"name"];
            NSLog(@"%@", fullName);
        }
    }
}];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!