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

发布于 2024-09-24 07:01:21 字数 1123 浏览 1 评论 0原文

我正在尝试从用户那里获取电子邮件地址。他登录,我请求访问电子邮件的权限,他选择“确定”。然后我使用 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";我做错了什么?

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.


- (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"; } What did I do wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蘑菇王子 2024-10-01 07:01:21

我找到了答案:

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

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"]);
   }
云醉月微眠 2024-10-01 07:01:21

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

Ah nevermind, it works. I had to use @"me" in [facebook requestWithGraphPath: @"me" andDelegate: self]; instead of the URL.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文