通过使用社交框架从Facebook获取基本信息(id,first_name) - 附加的源代码和屏幕截图 [英] Fetching basic information (id, first_name) from Facebook by using Social Framework - source code and screenshots attached

查看:284
本文介绍了通过使用社交框架从Facebook获取基本信息(id,first_name) - 附加的源代码和屏幕截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

稍后我会尝试通过使用社交框架获取有关玩家的基本信息:




  • id

  • first_name

  • 性别

  • 位置



(即不像电子邮件那样敏感,我不使用Facebook iOS SDK)。



所以在Xcode 5.0.2中,我为iPhone创建一个空白的单一视图应用程序,并将 Social.framework 添加到构建阶段选项卡。



然后我将以下代码添加到,对于Adobe AIR桌面和移动应用程序(但现在我尝试学习本地iOS编程),它工作得很好(从1-2年),我尝试了其id 262571703638 没有成功。



我已经添加了 FacebookAppID 根据Mohit10的建议,我认为只有Facebook SDK需要,而我尝试使用社交框架,但是它不能伤害到$ ...)



现在我得到调试器输出:

  2013-12-31 11:08:07.584 MyFacebook [3009:70b] Facebook可用:1 
2013-12-31 11:08:07.964 MyFacebook [3009:3903]基本访问授予

我只需要弄清楚,如何获取id,first_name,gender,location现在(如果 basic_info 是re

解决方案

您的代码有一些错误。




  • ACAccountStore * accountStore 正在超出范围,它应该是一个实例变量。

  • 您不需要用于发布的 ACFacebookAudienceKey

  • 需要 ACFacebookPermissionsKey 作为您想要的属性默认情况下可用



使用这些修复程序,您的代码仍然不为我工作,虽然它适用于我的应用程序ID。我收到以下错误:

 Facebook服务器无法完成此访问请求:无效的应用程序432298283565593UserInfo = 0x1d5ab670 { NSLocalizedDescription = Facebook服务器无法完成此访问请求:无效的应用程序432298283565593} 

看起来有什么问题与您的应用程序的Facebook配置。



唯一的区别是我的应用程序是沙盒,我使用我的开发者帐户登录。祝你好运。


For what would be a word game later I am trying to fetch very basic information about a player by using Social framework:

  • id
  • first_name
  • gender
  • location

(i.e. nothing sensitive like email and I don't use Facebook iOS SDK).

So in Xcode 5.0.2 I create a blank single view app for iPhone and add Social.framework to the Build phases tab.

Then I add the following code to the ViewController.m:

#import "ViewController.h"
#import <Social/Social.h>
#import <Accounts/Accounts.h>

#define FB_APP_ID @"432298283565593"
//#define FB_APP_ID @"262571703638"

@interface ViewController ()
@property (strong, nonatomic) ACAccountStore *accountStore;
@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSLog(@"Facebook is available: %d", [SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]);

    [self getMyDetails];
}

- (void) getMyDetails {
    if (!_accountStore) {
        _accountStore = [[ACAccountStore alloc] init];
    }

    ACAccountType *facebookAccountType = [_accountStore
                                        accountTypeWithAccountTypeIdentifier: ACAccountTypeIdentifierFacebook];
    NSDictionary *options = @{
                              ACFacebookAppIdKey: FB_APP_ID,
                              ACFacebookPermissionsKey: @[@"basic_info"]};

    [_accountStore requestAccessToAccountsWithType:facebookAccountType
                                           options:options
                                        completion:^(BOOL granted, NSError *error)
    {
        if (granted) {
            NSLog(@"Basic access granted");
        } else {
            NSLog(@"Basic access denied %@", error);
        }
    }];
}

@end

And create a new Facebook app for which I specify de.afarber.MyFacebook as the iOS Bundle ID:

Finally at Apple iTunes Connect I create a new App ID and then a new app (with a dummy icon and even 2 iPhone screenshots attached):

My Xcode Info tab and the rest of the source code are unchanged:

UPDATE 2:

I have updated the source code as suggested by helpful comments, thank you.

Also, I have another Facebook game, which works well (since 1-2 years) for an Adobe AIR desktop and mobile apps (but now I try to learn native iOS programming) and I have tried its id 262571703638 without success.

And I have added FacebookAppID to MyFacebook-Info.plist as suggested by Mohit10 (it seems to me that it is needed for Facebook SDK only, while I try to use Social Framework - but it can't hurt...)

Now I get the debugger output:

2013-12-31 11:08:07.584 MyFacebook[3009:70b] Facebook is available: 1
2013-12-31 11:08:07.964 MyFacebook[3009:3903] Basic access granted

I just need to figure out, how to fetch the id, first_name, gender, location now (and if basic_info is really needed for that)...

解决方案

There are a few things wrong with your code.

  • ACAccountStore *accountStore is going out of scope, it should be an instance variable.
  • You don't need the ACFacebookAudienceKey, that's for publishing.
  • You don't need the ACFacebookPermissionsKey as the properties you want are available by default

With these fixes your code still doesn't work for me, although it does work for my App ID. I get the the following error:

"The Facebook server could not fulfill this access request: Invalid application 432298283565593" UserInfo=0x1d5ab670 {NSLocalizedDescription=The Facebook server could not fulfill this access request: Invalid application 432298283565593}

Looks like there's something wrong with your app's Facebook configuration.

The only difference I can see is that my app is sandboxed and I'm logged in using my developer account. Good luck.

这篇关于通过使用社交框架从Facebook获取基本信息(id,first_name) - 附加的源代码和屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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