我创建了一个简单的应用程序,它使用FB Javascript SDK在FB上发布我的网页textareas中给出的内容。 我正在使用fb.api,问题是它只适用于我的用户ID(我从中创建了应用程序)。对于其他ID,它不起作用。有人可以帮忙吗?我希望其他用户也可以在登录后张贴在他们的墙上。
<html>
<head></head>
<body>
<div id="fb-root"></div>
<label>Give your message here:</label><br/>
<textarea id = "ta"></textarea><br/>
<label>Any image?</label><br/>
<textarea id = "pic"></textarea><br/>
<label>Any link?</label><br/>
<textarea id = "ta_link"></textarea><br/>
<button onclick = "testAPI()">Click To Post!</button>
<script>
// Additional JS functions here
window.fbAsyncInit = function() {
FB.init({
appId : 'AppID', // App ID
channelUrl : 'http://127.0.0.1/channel.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
// Additional init code here
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
alert("Connected");
//testAPI();
} else if (response.status === 'not_authorized') {
// not_authorized
login();
} else {
// not_logged_in
login();
}
});
};
function login() {
FB.login(function(response) {
if (response.authResponse) {
//testAPI();
} else {
alert("Can't connect")
}
});
}
function testAPI() {
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
var tbmsg = document.getElementById("ta").value;
var tbimg = document.getElementById("pic").value;
var tblink = document.getElementById("ta_link").value;
var wallPost = {};
wallPost['message'] = tbmsg;
if(tbmsg == "")
{
alert("Message box can't be empty")
}
if(tbimg)
{
wallPost['picture'] = tbimg;
}
if(tblink)
{
wallPost['link'] = tblink;
}
FB.api('/me/feed', 'post', wallPost , function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert("Posted");
}
});
}
else
{
alert("Login first")
}
}); }
// Load the SDK Asynchronously
</script>
</body>