如何使用 Facebook post 自定义 post javascript api
How to post a custom post using facebook javascript api
好的,我现在有一个带有输入和按钮的网站。当用户单击一个按钮时,我希望他的输入作为他 Facebook 帐户上的新提要。
我已经添加了 facebook javascript sdk 和 graph api 一个
我创建了一个成功的登录按钮和一个发送标准文本的新提要按钮 "is this is a text feed".
那么我如何 post 用户输入的内容?
posting的代码是
function postshare() {
FB.api(
"/me/feed",
"POST",
{
"message": "this is a test post"
},
function (response) {
if (response && !response.error) {
/* handle the result */
document.getElementById('poststt').innerHTML = 'post shared succesfully';
}
}
);
如果您在页面上有一个带有 ID 的文本输入,您可以引用该输入并使用 document.getElementById
获取它的值。所以如果你有这个输入
<input type="text" id="fb_input" />
在您的页面上,您可以这样做:
function postshare() {
var message = document.getElementById("fb_input").value;
FB.api(
"/me/feed",
"POST",
{
"message": message
},
function (response) {
if (response && !response.error) {
/* handle the result */
document.getElementById('poststt').innerHTML = 'post shared succesfully';
}
}
);
}
好的,我现在有一个带有输入和按钮的网站。当用户单击一个按钮时,我希望他的输入作为他 Facebook 帐户上的新提要。
我已经添加了 facebook javascript sdk 和 graph api 一个 我创建了一个成功的登录按钮和一个发送标准文本的新提要按钮 "is this is a text feed".
那么我如何 post 用户输入的内容?
posting的代码是
function postshare() {
FB.api(
"/me/feed",
"POST",
{
"message": "this is a test post"
},
function (response) {
if (response && !response.error) {
/* handle the result */
document.getElementById('poststt').innerHTML = 'post shared succesfully';
}
}
);
如果您在页面上有一个带有 ID 的文本输入,您可以引用该输入并使用 document.getElementById
获取它的值。所以如果你有这个输入
<input type="text" id="fb_input" />
在您的页面上,您可以这样做:
function postshare() {
var message = document.getElementById("fb_input").value;
FB.api(
"/me/feed",
"POST",
{
"message": message
},
function (response) {
if (response && !response.error) {
/* handle the result */
document.getElementById('poststt').innerHTML = 'post shared succesfully';
}
}
);
}