简体   繁体   English

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

[英]Can't get email address using facebook sdk for IOS and graph api for facebook

I am trying to get the email address from a user. 我想从用户那里获取电子邮件地址。 He logs in, I ask permission to access email and he chooses ok. 他登录,我请求访问电子邮件的权限,他选择确定。 Then I use the graph API from facebook to access the email address. 然后我使用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];
}

This is how i get the information: 这是我获取信息的方式:


- (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"];
    //...
  }
}

It gives me only this string: { id = "https://graph.facebook.com/me"; } 它只给我这个字符串: { id = "https://graph.facebook.com/me"; } { id = "https://graph.facebook.com/me"; } What did I do wrong? { id = "https://graph.facebook.com/me"; }我做了什么错?

I found answer: 我找到了答案:

 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"]);
   }

Ah nevermind, it works. 啊没关系,它有效。 I had to use @"me" in [facebook requestWithGraphPath: @"me" andDelegate: self]; 我不得不在[facebook requestWithGraphPath: @"me" andDelegate: self];使用@"me" [facebook requestWithGraphPath: @"me" andDelegate: self]; instead of the URL. 而不是URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM