Facebook Graph API,如何获取用户电子邮件? [英] Facebook Graph API, how to get users email?

查看:222
本文介绍了Facebook Graph API,如何获取用户电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Graph API,但我无法弄清楚如何获取登录用户的电子邮件地址。

I'm using the Graph API, but I can't figure out how to get a logged-in users email address.

图形介绍说 Graph API可以访问您通常以您的站点的注册表单的所有基本帐户注册数据,包括姓名,电子邮件地址,个人资料图片和生日

The intro to Graph states "The Graph API can provide access to all of the basic account registration data you would typically request in a sign-up form for your site, including name, email address, profile picture, and birthday"

一切都很好,但是如何访问该信息?

All well and good, but how do I access that info?

这是我到目前为止:

$json = $facebook->api('/me');

$first = $json['first_name']; // gets first name
$last = $json['last_name'];


推荐答案

获取用户电子邮件地址的唯一方法是要求电子邮件字段的扩展权限。用户必须允许您看到这一点,您无法获取用户朋友的电子邮件地址。

The only way to get the users e-mail address is to request extended permissions on the email field. The user must allow you to see this and you cannot get the e-mail addresses of the user's friends.

http://developers.facebook.com/docs/authentication/permissions

你可以如果您正在使用Facebook连接,请通过将您的呼叫的获取字符串传递给Auth对话框来使用Facebook连接。

You can do this if you are using Facebook connect by passing scope=email in the get string of your call to the Auth Dialog.

我建议使用 SDK ,而不是file_get_contents,因为它更容易执行 Oauth 认证。

I'd recommend using an SDK instead of file_get_contents as it makes it far easier to perform the Oauth authentication.

这篇关于Facebook Graph API,如何获取用户电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆