1
我正在使用Facebook iOS SDK和Facebook Graph API。當我請求「我」,它應該返回當前用戶的所有屬性,我實際上只是獲取用戶對象的一小部分。我究竟做錯了什麼?如何使用Facebook Graph API和facebook ios sdk獲取完整的用戶對象?
我在登錄時也沒有收到Allow/Do not Allow對話框,但也許是因爲我是應用程序所有者?
在我的頭:
#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;
}