首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用ACAccount为iOS 7获取电子邮件

使用ACAccount为iOS 7获取电子邮件
EN

Stack Overflow用户
提问于 2013-10-31 19:54:44
回答 2查看 2.8K关注 0票数 2

首先,我不想使用Facebook,所以我设法做到了这一点,这是可行的,但我不知道如何检索用户的电子邮件,即使它是在我的权限请求。

代码语言:javascript
复制
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完成,却找不到它。

有可能吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-10-31 22:49:13

为了从Facebook获取用户的电子邮件地址,您必须使用图API来使用社会框架查询当前用户

代码语言:javascript
复制
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);
        }
    }
}];
票数 5
EN

Stack Overflow用户

发布于 2015-11-18 07:36:56

现在,您需要在GET请求中通过param。默认情况下,只有ID和名称。

代码语言:javascript
复制
NSDictionary *param = @{@"fields":@"email,name"};

SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                                     requestMethod:SLRequestMethodGET
                                                               URL:[NSURL URLWithString:@"https://graph.facebook.com/me"]
                                                        parameters:param];
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19715489

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档