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