我正在使用LinkedIn Javascript API将用户登录到我的应用程序,但是即使我需要该特定字段的权限,API也不会返回电子邮件地址。我包含 API 脚本,如下所示:
<script type="text/javascript" src="//platform.linkedin.com/in.js">
api_key: API_KEY
scope: r_fullprofile r_emailaddress
</script>
然后我在标记中包含登录按钮:
<script type="in/Login" data-onAuth="onLinkedInAuth">
最后,我有一个函数来添加 API 响应的回调:
function onLinkedInAuth() {
var fields = ['first-name', 'last-name', 'email-address'];
IN.API.Profile("me").fields(fields).result(function(data) {
console.log(data);
}).error(function(data) {
console.log(data);
});
};
我只得到名字和姓氏,但 API 不返回电子邮件字段。
参考: https://developer.linkedin.com/documents/profile-fields#email
1- 确保您在应用程序中获得了电子邮件权限 (r_emailaddress http://developer.linkedin.com/documents/authentication#granting
2-然后你可以使用它
<script type="text/javascript" src="http://platform.linkedin.com/in.js">
api_key: key
**onLoad: onLinkedInLoad**
authorize: true
</script>
<script>
function onLinkedInLoad() {
IN.Event.on(IN, "auth", onLinkedInAuth);
}
// 2. Runs when the viewer has authenticated
function onLinkedInAuth() {
IN.API.Profile("me").fields("first-name", "last-name", "email-address").result(function (data) {
console.log(data);
}).error(function (data) {
console.log(data);
});
}
</script>
希望这对你:)有所帮助谢谢
你好,@Ulises菲格罗亚,可能是我来得有点晚了,但这就是我完成这项工作的方式:
从页面顶部 head 部分中的初始脚本标记开始:
<script>
Client Id Number here:
onLoad: onLinkedInLoad
authorize: true
</script>
然后,在您的JS文件中(我放置了一个外部JS文件来处理此API注册/身份验证),放置以下详细信息:
function onLinkedInLoad() {
IN.Event.on(IN, "auth", getProfileData);
}
function onSuccess(data) {
console.log(data);
}
function onError(error) {
console.log(error);
}
function getProfileData(){
IN.API.Profile("me").fields(["firstName","lastName", "email-address", "positions"]).result(function(data) {
var profileData = data.values[0];
var profileFName = profileData.firstName;
var profileLName = profileData.lastName;
if(data.values[0].positions._total == "0" || data.values[0].positions._total == 0 || data.values[0].positions._total == undefined) {
console.log("Error on position details");
var profileCName = "Details Are Undefined";
}
else {
var profileCName = profileData.positions.values["0"].company.name;
}
var profileEName = profileData.emailAddress;
//console.log all the variables which have the data that
//has been captured through the sign up auth process and
//you should get them...
});
}
最后但并非最不重要的一点是,在您的 HTML 文档中添加以下内容,这可以帮助您启动LinkedIn身份验证注册表单的窗口弹出窗口:
<script type="in/Login"></script>
上述设置对我有用。当然,这会帮助你。
干杯,祝你有美好的一天。
实现看起来不错。我相信这是个人资料隐私设置的结果。根据链接的文档:
并非所有字段都可用于所有配置文件。可用字段取决于您代表其发出请求的用户与成员之间的关系、成员选择提供的信息及其隐私设置。不应假定为给定成员返回除 id 以外的任何内容。
我发现这只发生在某些LinkedIn帐户上,所以这可能是因为电子邮件的某些隐私设置造成的。我找不到对文档的任何引用,因此我不得不考虑电子邮件字段不可用的情况。