通过我的网站发布到 Facebook 墙上
Posted
技术标签:
【中文标题】通过我的网站发布到 Facebook 墙上【英文标题】:Post to facebook wall through my website 【发布时间】:2013-10-09 18:22:39 【问题描述】:当我在文本框中输入一些内容并上传图片并提交时,帖子应该发布在特定用户的 Facebook 时间线中。这是我编写的代码,但它不起作用:
<html>
<head>
<script src='http://connect.facebook.net/en_US/all.js'></script>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function()
FB.init(
appId : 'App ID', // App ID
channelUrl : '//mynetwork.net/', // 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')
testAPI();
else if (response.status === 'not_authorized')
FB.login();
else
FB.login();
);
;
(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));
function testAPI()
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response)
console.log('Good to see you, ' + response.name + '.');
);
</script>
<script>
var params = ;
params['message'] = 'Message eqwe';
params['name'] = 'wqe wqeweq Name';
params['description'] = 'wqe wDescription';
params['link'] = 'https://www.facebook.com/nvidarshana?fref=ts';
params['picture'] = 'http://summer-mourning.zoocha.com/uploads/thumb.png';
params['caption'] = 'Caption';
FB.api('/me/feed', 'post', params, function(response)
if (!response || response.error)
console.log(response.error);
alert(response.error);
else
alert('Published to stream - you might want to delete it now!');
);
</script>
<fb:login-button show-faces="true" max-rows="1"></fb:login-button>
</body>
</html>
我更新了代码,还是报错
"Object message:"必须使用主动访问令牌来查询当前用户的信息。", type: "OAuthException", code: 2500"
【问题讨论】:
【参考方案1】:如果您的用户正在会话中,请替换以下代码-
FB.api('/My_Access_Token/feed'
与 -
FB.api('/me/feed'
【讨论】:
你能告诉我确切的错误吗?console.log(response)
。 FB
定义了吗?
'发生错误'这是我每次得到的。您所说的“FB 定义”是什么意思,我在上面发布了我的完整代码。我应该如何定义FB?
不要使用alert('Error occured');
——写alert(response.error)
并告诉我确切的错误
写concole.log(response.error)
,然后检查浏览器控制台中的值(Shift+Ctrl+j
,如果是chrome)
Object message: "一个活动的访问令牌必须用于查询当前用户的信息。", type: "OAuthException", code: 2500【参考方案2】:
在您想在墙上显示按钮的任何位置插入下面的代码。编辑相关文本。
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function()
FB.init(appId: "YOUR APP ID FROM STEP 3", status: true, cookie: true,
xfbml: true);
;
(function()
var e = document.createElement("script"); e.async = true;
e.src = document.location.protocol +
"//connect.facebook.net/en_US/all.js";
document.getElementById("fb-root").appendChild(e);
());
function streamPublish()
FB.ui(
method: 'stream.publish',display:'popup';
<dd>
message: 'getting educated about Facebook Connect',
attachment:
name: 'Connect',
caption: 'The Facebook Connect javascript SDK',
description: (
'A small JavaScript library that allows you to harness ' +
'the power of Facebook, bringing the user\'s identity, ' +
'social graph and distribution power to your site.'
),</dd>
‘media’: [ 'type': 'image',
'src': 'http://www.yoursite.com/images/facebook_icon.png',
'href': fb_root()] ,
<dd>
href: 'http://github.com/facebook/connect-js'
,
action_links: [
text: 'Code', href: 'http://github.com/facebook/connect-js'
],
user_message_prompt: 'Share your thoughts about Connect'
,
function(response)
if (response && response.post_id)
alert('Post was published.');
else
alert('Post was not published.');
);
</script>
</dd>
<dd></dd>
通过链接调用streamPublish函数。您可以使用 CSS 更改链接/按钮的外观。
<a onclick=”streamPublish();” >Click to Publish on Facebook wall</a>
如果没有弹出发布窗口,请尝试将 display: value 设置为“对话框”
【讨论】:
欣赏!!我添加我的 APP ID 并更改图像,并将链接更改为 '单击以在 Facebook 墙上发布' 但单击链接时没有任何反应。我也会检查 display:‘dialog’ ..以上是关于通过我的网站发布到 Facebook 墙上的主要内容,如果未能解决你的问题,请参考以下文章
如何在我的 Facebook 墙上同时发布图像数据和网站 URL
每天通过 Magento 将网站内容发布到 Facebook Wall