如何使用 Facebook Graph API 和 facebook ios sdk 获取完整的 User 对象?
我正在使用 Facebook iOS SDK 和 Facebook Graph API。当我请求“me”时(它应该返回当前用户的所有属性),我实际上只获得了 User 对象的一小部分。我做错了什么?
当我登录时,我也没有收到“允许/不允许”对话框,但这也许是因为我是应用程序所有者?
在我的标题中:
#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;
}
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 fields 参数和任何记录的用户字段。
@“我?fields=id,姓名,性别,...”
Use the fields parameter and any of the documented user fields.
@"me?fields=id,name,gender,..."