无法从OAuth iOS中提取用户的Facebook电子邮件地址

时间:2012-04-18 11:08:33

标签: ios facebook email sdk oauth

你能帮助一些困在这里,让我们先看看代码, 在这里我要求权限

 NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithCapacity:0];
    [params setObject:facebook._appId forKey:@"client_id"];
    [params setObject:@"token" forKey:@"response_type"];
    [params setObject:[NSString stringWithCString:"email,user_about_me,read_stream,publish_stream,offline_access" encoding:NSUTF8StringEncoding] forKey:@"scope"];
    [facebook dialog:@"oauth" andParams:params andDelegate:self];
    [params release];

此处使用@“me”表示图谱API

- (void)fbDidLogin 
{
    [facebook requestWithGraphPath:@"me" andDelegate:self];

}

但我得到的只是

- (void)request:(FBRequest *)request didLoad:(id)result
{
    [UIApplication sharedApplication].networkActivityIndicatorVisible=NO;
    NSLog(@"FB result %@", result);
}

FB结果(     “Justfortest Workingin”,     100002369945695 )

但如何获取电子邮件地址?

2 个答案:

答案 0 :(得分:0)

facebook = [[Facebook alloc] initWithAppId:kYourAppID andDelegate:self];    
NSArray *permissions = [[NSArray alloc] initWithObjects:@"publish_stream",@"publish_actions", @"email",@"user_about_me",@"offline_access",nil];
[facebook authorize:permissions];
[permissions release];

然后你应该得到你需要的一切

对于对话而不是网络浏览器,这就是您所需要的:

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:10];
[params setObject:kFBAppId forKey:@"client_id"];
[params setObject:@"publish_stream,email,offline_access" forKey:@"scope"];
// Now popup the login dialog
[facebook dialog:@"oauth" andParams:params andDelegate:self];

答案 1 :(得分:0)

正确的答案是,fb不会使用

返回电子邮件和其他数据
[facebook requestWithGraphPath:@"me" andDelegate:self];

只有id和name。

我需要简单地加入

- (void)request:(FBRequest *)request didLoad:(id)result

另一个用户数据调用。

最后需要的方法如下:

    - (void)request:(FBRequest *)request didLoad:(id)result
    {
        NSData * dt = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/me/?access_token=%@",facebook.accessToken]]];
        NSDictionary *response = (NSDictionary*)[[JSONDecoder decoder] objectWithData:dt];
        NSLog(@"fb response %@",response);
        if ([response objectForKey:@"email"]) {
            [[NSUserDefaults standardUserDefaults] setValue:[response objectForKey:@"email"] forKey:@"fbEmail"];
            [[NSUserDefaults standardUserDefaults] setValue:[response objectForKey:@"id"] forKey:@"fbId"];
            [[NSUserDefaults standardUserDefaults] setValue:facebook.accessToken forKey:@"fbToken"];
            [[NSUserDefaults standardUserDefaults] setValue:facebook.expirationDate forKey:@"fbExDate"];
            [[NSUserDefaults standardUserDefaults] synchronize];
        }
    }

我得到了所有用户数据,请大家帮忙,希望这对某人有帮助。 也是来自http://midatlanticconsulting.com的帮助我解决这个问题的人。