首先,我不想使用Facebook,所以我设法做到了这一点,这是可行的,但我不知道如何检索用户的电子邮件,即使它是在我的权限请求。
ACAccountStore *account = [[ACAccountStore alloc] init];
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:accountTypeName];
NSDictionary *options;
if ( [accountTypeName isEqualToString:ACAccountTypeIdentifierFacebook]){
options = @{
ACFacebookAppIdKey: @"601517946570890"
,ACFacebookPermissionsKey: @[@"email"]
};
}
[account requestAccessToAccountsWithType:accountType options:options completion:^(BOOL granted, NSError *error)
{
if (granted == YES)
{
NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType];
if ([arrayOfAccounts count] > 0)
{
_account = [arrayOfAccounts lastObject];
NSDictionary *dict = @{
@"name": [_account userFullName] == nil ? [_account username] : [_account userFullName],
@"account_id": [_account identifier],
@"email": @"??"
};
NSLog(@"account info: %@",dict);
}
}
}];ACAccount上没有返回用户电子邮件的属性,所以我试图查找它是否必须通过SLRequest完成,却找不到它。
有可能吗?
发布于 2013-10-31 22:49:13
为了从Facebook获取用户的电子邮件地址,您必须使用图API来使用社会框架查询当前用户:
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 *email = userData[@"email"];
NSLog(@"%@", email);
}
}
}];发布于 2015-11-18 07:36:56
现在,您需要在GET请求中通过param。默认情况下,只有ID和名称。
NSDictionary *param = @{@"fields":@"email,name"};
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodGET
URL:[NSURL URLWithString:@"https://graph.facebook.com/me"]
parameters:param];https://stackoverflow.com/questions/19715489
复制相似问题