【问题标题】:Get Facebook uid from ACAccountStore in iOS?从 iOS 的 ACAccountStore 获取 Facebook uid?
【发布时间】:2013-02-03 19:25:26
【问题描述】:

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

    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,但我无法获取...

【问题讨论】:

    标签: iphone xcode facebook ios6 social-framework


    【解决方案1】:

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

        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);
    
                 }
             }];
    

    【讨论】:

    • 请注意,properties.uid 中的 UID 可能与 /me 图形调用中返回的 UID 不同。
    • @chrysb 我知道这是一个旧线程,但你能详细说明这是为什么吗? Apple 文档中是否提到过它?
    • 这是 Facebook 的事情。他们正在转向特定于应用的用户 ID,这将不同于您的规范用户 ID。
    【解决方案2】:

    您需要拨打Facebook Graph API;使用 SLRequest 如下:

    NSUrl requestURL = NSUrl.FromString("https://graph.facebook.com/me"); 
    SLRequest sl = SLRequest.Create(SLServiceKind.Facebook, SLRequestMethod.Get, requestURL, null);
    
    sl.Account = // your ACAccount object here
    
    sl.PerformRequest((data, response, error) => {
        if (error == null) {
            // success! parse response
        }
        else {
            // handle failure
        }
    });
    

    应该这样做!

    【讨论】:

    • 嘿,谢谢你的回答,但我想在不调用 Facebook Graph API 的情况下得到它。
    猜你喜欢
    • 2013-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多