开发者

How do I get the full User object using Facebook Graph API and facebook ios sdk?

I'm using the Facebook iOS S开发者_高级运维DK 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?

In my header:

#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

In my implementation:

#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;
}


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜