使用facebook sdk获取IOS和图api for facebook无法获取电子邮件地址

时间:2010-09-23 09:57:32

标签: iphone objective-c facebook facebook-graph-api

我正在尝试从用户那里获取电子邮件地址。他登录,我请求访问电子邮件的权限,他选择确定。然后我使用Facebook的图形API来访问电子邮件地址。


- (void) fbDidLogin
{
  btnLogin.isLoggedIn = TRUE;
  [btnLogin updateImage];

  NSString *theURL = 
  [ [NSString stringWithFormat: 
    @"https://graph.facebook.com/me?access_token=%@", facebook.accessToken
    ]stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding
  ];

  NSLog(@"%@", theURL);
  [facebook requestWithGraphPath: theURL andDelegate: self];
}

...

- (void)request:(FBRequest*)request didLoadRawResponse:(NSData*)data
{
  NSString *response = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
  NSLog(@"%@", response);
  [response release];
}

这就是我获取信息的方式:


- (void) request:(FBRequest*)request didLoad:(id)result
{
  if ([result isKindOfClass:[NSDictionary class]])
  {
    NSString *email = [result objectForKey: @"email"];
    NSString *name = [result objectForKey: @"name"];
    NSString *facebookId = [result objectForKey: @"id"];
    //...
  }
}

它只给我这个字符串:{ id = "https://graph.facebook.com/me"; }我做错了什么?

2 个答案:

答案 0 :(得分:9)

我找到了答案:

 NSArray *permissions = [[NSArray alloc] initWithObjects:@"user_likes",@"offline_access",@"read_stream",@"publish_stream",@"email",nil];

  [facebook requestWithGraphPath:@"me"andParams:params andDelegate:self];
  -(void)facebookLoginScreen:(NSDictionary *)result
   {
        NSLog(%@,[result objectForKey:@"email"]);
   }

答案 1 :(得分:4)

啊,没关系,它有效。我必须在@"me"中使用[facebook requestWithGraphPath: @"me" andDelegate: self];而不是网址。