问题
i want retrieve the information of a facebook account on the ios 6 integrated Facebook, now i do it in this way and i can retrieve only the username:
ACAccountType *accountTypeF = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
if(granted) {
NSArray *accountsArray = [accountStore accountsWithAccountType:accountTypeF];
ACAccount *facebookAccount = [accountsArray objectAtIndex:0];
if (facebookAccount.username) {
}
}
}];
i want know how i can retrieve also the Name and Surname of the account and the pic of the user...anyone can help me?
回答1:
Jeffrey is right. Go to this post: Facebook iOS 6 - get user info and implement 2 methods given by Daniel.
After then make sure to make some changes in your application settings on facebook developer account
.
- On main settings page disable
sandbox mode
- Put your applications
bundle id
Enable
facebook login
Then go to Advance
settings on the left
- Select
Native/Desktop
asApp Type
- make sure
App secret in client
isNO
Save all settings and it really takes few minutes to populate the changes on server. Finally Must reset you simulator
回答2:
ACAccount
is a generic "social" class provided by Apple; it has only limited account information and no knowledge of Facebook data. After obtaining the account, you can instantiate an SLRequest
to query the Facebook Graph API, using the account to authenticate it...
NSURL* URL = [NSURL URLWithString:@"https://graph.facebook.com/me"];
SLRequest* request = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodGET
URL:URL
parameters:nil];
[request setAccount:account]; // Authentication - Requires user context
[request performRequestWithHandler:^(NSData* responseData, NSHTTPURLResponse* urlResponse, NSError* error) {
// parse the response or handle the error
}];
来源:https://stackoverflow.com/questions/12539549/retrieve-facebook-account-information-in-ios-6