gpt4 book ai didi

javascript - 是否仍然可以获得 Facebook 好友电子邮件列表?

转载 作者:行者123 更新时间:2023-11-30 21:13:51 25 4
gpt4 key购买 nike

您好,请帮助我运行下面的代码来获取用户的详细信息,例如姓名和电子邮件,但是否也可以获取他们的 FB friend 的电子邮件?也许改变这个

FB.api('/me', {fields: 'name,email'}*

进入这个

FB.api('/me/friends', {fields: 'name,email'} ?

并在控制台中将其显示为这样的数组?

[{email: 'someone0@email.com'},
{email: 'someone1@email.com'},
{email: 'someone2@email.com'},
{email: 'someone3@email.com'}]

您可以从这里测试示例页面:https://domain/referral

<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'xxxxxxxxxxxxxxxxxx', // Set YOUR APP ID
// channelUrl : 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});

FB.Event.subscribe('auth.authResponseChange', function(response)
{
if (response.status === 'connected')
{
document.getElementById("message").innerHTML += "<br>Connected to Facebook";
//SUCCESS

}
else if (response.status === 'not_authorized')
{
document.getElementById("message").innerHTML += "<br>Failed to Connect";

//FAILED
} else
{
document.getElementById("message").innerHTML += "<br>Logged Out";

//UNKNOWN ERROR
}
});

};

function Login()
{

FB.login(function(response) {
if (response.authResponse)
{
getUserInfo();
} else
{
console.log('User cancelled login or did not fully authorize.');
}
},{scope: 'email,user_photos,user_videos,user_friends'});

}


function getUserInfo() {
FB.api('/me',{fields: 'name,email'}, function(response) {

var str="<b>Name</b> : "+response.name+"<br>";
str +="<b>Email:</b> "+response.email+"<br>";
str +="<input type='button' value='Get Friends' onclick='getFriends();'/>";
str +="<input type='button' value='Get Photo' onclick='getPhoto();'/>";
str +="<input type='button' value='Logout' onclick='Logout();'/>";
document.getElementById("status").innerHTML=str;

});
}

function getFriends() {
FB.api('/me/friends',{fields: 'name,email'}, function(response) {
if(response.data) {
$.each(response.data,function(index,friend) {
console.log(friend.name + ' has email:' + friend.email);
});
} else {
alert("Error!");
}
});
}
function getPhoto(){
FB.api('/me/picture?type=normal', function(response) {

var str="<br/><b>Pic</b> : <img src='"+response.data.url+"'/>";
document.getElementById("status").innerHTML+=str;

});
}

function Logout() {
FB.logout(function(){document.location.reload();});
}

// Load the SDK asynchronously
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
</script>

<div align="center">
<h2>Facebook OAuth</h2>
<div id="status">
<img src="http://hayageek.com/examples/oauth/facebook/oauth-javascript/LoginWithFacebook.png" style="cursor:pointer;" onclick="Login()"/>
</div>
<br/><br/><br/><br/><br/>
<div id="message">
Logs:<br/>
</div>
</div>

最佳答案

你检查了吗? https://developers.facebook.com/docs/graph-api/reference/user/

如果我在 https://developers.facebook.com/tools/explorer/ 中做你做的事

Facebook 给出的响应

Query

curl -i -X GET "https://graph.facebook.com/v2.10/me/friends?access_token=<accesstoken sanitized>"

Response

{
"data": [],
"summary": {
"total_count": 8
},
"__debug__": {
"messages": [
{
"link": "https://developers.facebook.com/docs/apps/changelog#v2_0",
"message": "Only friends who installed this app are returned in API v2.0 and higher. total_count in summary represents the total
number of friends, including those who haven't installed the app.",
"type": "info"
}
]
} }

Debug Information from Graph API Explorer

有没有看到

Only friends who installed this app are returned in API v2.0 and higher. > total_count in summary represents the total number of friends, including those who haven't installed the app

所以你不能像这样交 friend 。就像 @CBroe 说的那样

A user’s email is only accessible after they personally grant your app permission.

关于javascript - 是否仍然可以获得 Facebook 好友电子邮件列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45874142/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com