如何使用Facebook Graph API和facebook ios sdk获取完整的User对象? [英] How do I get the full User object using Facebook Graph API and facebook ios sdk?

查看:105
本文介绍了如何使用Facebook Graph API和facebook ios sdk获取完整的User对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Facebook iOS SDK 和Facebook Graph API。当我请求我,它应该返回当前用户的所有属性,我只是实际上得到一个小的User对象子集。我做错了什么?

I'm using the Facebook iOS SDK and Facebook Graph API. When I request "me", which should return all the properties of the current user, I'm only actually getting a small subset of the User object. What am I doing wrong?

我登录时还没有收到允许/不允许对话框,但也许是因为我是应用程序的所有者

I'm also not getting the Allow / Don't Allow dialog when I log in, but perhaps that is because I am the app owner?

在我的标题中:

#import <UIKit/UIKit.h>
#import "Facebook.h"

@interface FacebookAppViewController : UIViewController <FBRequestDelegate, FBDialogDelegate, FBSessionDelegate> {
    Facebook* facebook;
    NSArray* permissions;

    IBOutlet UILabel* JSONLabel;
}

@property (retain, nonatomic) UILabel* JSONLabel;

- (IBAction)login:(id)sender;
- (IBAction)logout:(id)sender;

@end

在我的实现中:

#import "FacebookAppViewController.h"

static NSString* apiKey = @""; // with my app ID

@implementation FacebookAppViewController

@synthesize JSONLabel;

- (IBAction)login:(id)sender
{
    [facebook authorize:apiKey permissions:permissions delegate:self];
}

- (void) fbDidLogin
{
    [facebook requestWithGraphPath:@"me" andDelegate:self];
}

- (void)request:(FBRequest*)request didLoad:(id)result
{
    NSString* uid = [result objectForKey:@"id"];

    if ([result isKindOfClass:[NSDictionary class]])
    {
        NSString* text = @"";
        NSDictionary* hash = result;

        for (NSString* key in hash)
        {
            text = [text stringByAppendingFormat:@"\n%@: ", key];

            NSObject* value = [hash objectForKey:key];
            if (value == nil)
            {
                NSLog(@"value is nil");
                continue;
            }

            if ([value isKindOfClass:[NSString class]])
            {
                NSString* str = value;
                text = [text stringByAppendingFormat:@"%@", str];
            }
            JSONLabel.text = text;
        }
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];

    facebook = [[Facebook alloc] init];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        permissions = [[NSArray arrayWithObjects:@"read_stream", @"offline_access", nil] retain];
    }
    return self;
}


推荐答案

使用fields参数和任何的文档用户字段。
@me?fields = id,name,gender,...

Use the fields parameter and any of the documented user fields. @"me?fields=id,name,gender,..."

这篇关于如何使用Facebook Graph API和facebook ios sdk获取完整的User对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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