无法使用适用于 IOS 的 facebook sdk 和适用于 facebook 的图 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";我做错了什么?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了答案:
I found answer:
啊,没关系,它有效。我必须在
[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.