我正在尝试访问某些用户的信息,包括电子邮件。为此,我使用 Graph API 来调用此方法:
[facebook requestWithGraphPath:@"me" andDelegate:self];
它返回用户信息,没有电子邮件信息(生日也丢失了)。我设置了所有权限并使用多个帐户(具有电子邮件和生日作为公共信息)进行了测试,并接受了所有对话的请求。
这是我的初始化:
if(!facebook) {
facebook = [[Facebook alloc] initWithAppId:[self _APP_KEY] andDelegate:self];
NSArray *array = [NSArray arrayWithObjects: @"email", @"user_birthday", @"publish_stream", @"offline_access", nil];
[self setPermissions:array];
}
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"]) {
facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
}
if (![facebook isSessionValid]) {
[facebook authorize:permissions];
}
else {
[self getUserInfo];
}
登录回调:
- (void)fbDidLogin {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];
[self getUserInfo];
}
getUserInfo 方法:
- (void) getUserInfo {
[facebook requestWithGraphPath:@"me" andDelegate:self];
}
请求回调:
- (void)request:(FBRequest *)request didLoad:(id)result {
if ([result isKindOfClass:[NSDictionary class]]) {
NSDictionary* json = result;
NSLog(@"-> %@", json);
}
}
结果如下:
-> {
"first_name" = EDITED (my name);
gender = male;
hometown = {
id = 111072692249998;
name = "Porto Alegre";
};
id = 653099452;
languages = (
{
id = 104034306299811;
name = "Brazilian Portuguese";
},
{
id = 106059522759137;
name = English;
}
);
"last_name" = EDITED (my last name);
link = EDITED (my profile);
locale = "en_US";
location = {
id = 112047398814697;
name = "S\U00e3o Paulo, Brazil";
};
name = EDITED (my name);
timezone = "-3";
"updated_time" = "2012-04-25T13:36:51+0000";
verified = 1;
}
如您所见,没有关于用户电子邮件的信息。我错过了一些步骤吗?有什么想法吗?
提前致谢