从iOS的ACAccountStore获取Facebook uid? [英] Get Facebook uid from ACAccountStore in iOS?

查看:330
本文介绍了从iOS的ACAccountStore获取Facebook uid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我想从iOS 6中的 ACAccountStore 获取Facebook用户的UID

Hi i want to get the Facebook user's UID from ACAccountStore in iOS 6

    self.accountStore = [[ACAccountStore alloc]init];

    ACAccountType *FBaccountType= [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

    NSString *key = @"01234567890123";
    NSDictionary *dictFB = [NSDictionary dictionaryWithObjectsAndKeys:key,ACFacebookAppIdKey,@[@"email"],ACFacebookPermissionsKey, nil];


        [self.accountStore requestAccessToAccountsWithType:FBaccountType options:dictFB completion:
         ^(BOOL granted, NSError *e) {
             if (granted) {
                 NSArray *accounts = [self.accountStore accountsWithAccountType:FBaccountType];

                 //it will always be the last object with single sign on
                 self.facebookAccount = [accounts lastObject];

                 //i Want to get the Facebook UID and log it here

                 NSLog(@"facebook account =%@",self.facebookAccount);

             } else {
                 //Fail gracefully...
              NSLog(@"error getting permission %@",e);

             }
         }];

self.facebookAccount 有UID,但我无法得到它。 ..

self.facebookAccount has UID, but i am unable to get it...

推荐答案

我想在不使用Facebook API的情况下获取UID。它可以通过使用以下方法完成

I wanted to get the UID without using the Facebook API. It can done by using the following method

    self.accountStore = [[ACAccountStore alloc]init];

    ACAccountType *FBaccountType= [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

    NSString *key = @"01234567890123";
    NSDictionary *dictFB = [NSDictionary dictionaryWithObjectsAndKeys:key,ACFacebookAppIdKey,@[@"email"],ACFacebookPermissionsKey, nil];


        [self.accountStore requestAccessToAccountsWithType:FBaccountType options:dictFB completion:
         ^(BOOL granted, NSError *e) {
             if (granted) {
                 NSArray *accounts = [self.accountStore accountsWithAccountType:FBaccountType];

                 //it will always be the last object with single sign on
                 self.facebookAccount = [accounts lastObject];

                 //i  got the Facebook UID and logged it here (ANSWER)

                  NSLog(@"facebook account =%@",[self.facebookAccount valueForKeyPath:@"properties.uid"]);

             } else {
                 //Fail gracefully...
              NSLog(@"error getting permission %@",e);

             }
         }];

这篇关于从iOS的ACAccountStore获取Facebook uid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆