1

你能帮忙解决一些卡在这里,让我们先看代码,这里我请求权限

 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)

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

4

2 回答 2

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

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

对于对话框而不是 Web 浏览器,这是您需要的:

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];
于 2012-04-18T11:46:12.727 回答
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的人,他们帮助我解决了这个问题。

于 2012-05-04T14:51:01.340 回答