我一直在尝试使用测试用户帐户获取新闻提要同时根据Facebook它拥有所有权限。但我没有这样做。我不确定facebook条款。这是我的整个代码哪个工作得很好但是它没有在News Feed响应中返回Null响应数组。我的剧本。
window.fbAsyncInit = function() {
FB.init({
appId : '1476612739307123', // App ID
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: 'publish_actions',
return_scopes: true});
}
function getUserInfo() {
FB.api('/me', {fields: 'id,link,name,first_name,last_name,email,gender'},function(response) {
console.log(response);
var str="<b>Name</b> : "+response.name+"<br>";
str +="<b>First Name</b> : "+response.first_name+"<br>";
str +="<b>Last Name</b> : "+response.last_name+"<br>";
str +="<b>Link: </b>"+response.link+"<br>";
str +="<b>Username:</b> "+response.gender+"<br>";
str +="<b>id: </b>"+response.id+"<br>";
str +="<b>Email:</b> "+response.email+"<br>";
str +="<input type='button' value='Get Photo' onclick='getPhoto();'/>";
str +="<input type='button' value='Logout' onclick='Logout();'/>";
document.getElementById("details").innerHTML=str;
});
}
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;
});
FB.api(
"/me/feed",
{
"filter":"nf"
}
,function (response) {
if (response && !response.error) {
console.log(response);
} else{ console.log(response.error); alert();}
}
);
}
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));
Cosole返回的响应数组
data[]
我的HTML代码:
<div id="status">
Click on Below Image to start the demo: <br/>
<img src="http://hayageek.com/examples/oauth/facebook/oauth-javascript/LoginWithFacebook.png" style="cursor:pointer;" onclick="Login()"/>
请回答有关Facebook权限的问题。在此先感谢。