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

北城余情 提交于 2019-12-08 07:14:43

问题


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?

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

回答1:


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



来源:https://stackoverflow.com/questions/4110352/how-do-i-get-the-full-user-object-using-facebook-graph-api-and-facebook-ios-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!