bbe*_*ord 4 ajax jquery facebook facebook-graph-api
把头发拉过这一个.
我正在编写一个连接Facebook的网络应用程序,最终会将一些任意信息发布到整个过程中选择的朋友的墙上.
我现在处于最后阶段并希望张贴到墙上会很简单,但我花了很长时间试图解决这个问题,所以我希望有人可以帮助我.
我试图像这样使用ajax发布:
$.ajax({
type: 'POST',
url: "https://graph.facebook.com/bbeckford/feed",
data: {message: wallMessage, target_id: friendID, access_token: "<?= $cookie['access_token'] ?>", format: "json"},
success: function(data) { alert(data); },
dataType: "JSON"
});
Run Code Online (Sandbox Code Playgroud)
但我只是不断收到这个错误:"XMLHttpRequest无法加载https://graph.facebook.com/bbeckford/feed.来自Access-Control-Allow-Origin不允许来源http://www.secretsantasetup.com."
我已经完成了搜索,一个建议是制作一个php代理,这是一个可行的选择吗?我该怎么做呢?
我接近这个完全错了吗?
任何帮助将不胜感激,谢谢,-Ben
编辑 我想在后台执行此操作,例如用户选择了10个朋友,然后提交应用程序将循环通过每个朋友并在他们的墙上发布一些东西.这可能吗?谢谢!
编辑2 下一页底部的测试控制台完全符合我的要求,但没有源代码?- http://developers.facebook.com/docs/reference/rest/stream.publish
在这里,您将使用javaScript SDK
步骤1
首先,您的应用程序应获得在用户墙或用户的朋友墙上发布的权限.
来自Facebook的示例代码: 链接
FB.login(function(response) {
if (response.session) {
if (response.perms) {
// user is logged in and granted some permissions.
// perms is a comma separated list of granted permissions
} else {
// user is logged in, but did not grant any permissions
}
} else {
// user is not logged in
}
}, {perms:'read_stream,publish_stream,offline_access'});
Run Code Online (Sandbox Code Playgroud)
需要在用户或用户的朋友墙上发布publish_stream.
需要编辑的行:{perms:'read_stream,publish_stream,offline_access'})
要阅读有关其他权限的更多信息:链接
第2步
取自Facebook JavaScript SDK页面和调整链接
FB.ui(
{
method: 'stream.publish',
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.'
),
href: 'http://github.com/facebook/connect-js'
},
target_id: 'ENTER YOU FRIENDS IDS - more than one, seperate by commas',
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.');
}
}
);
Run Code Online (Sandbox Code Playgroud)
需要编辑或添加的行:target_id:'输入您的朋友IDS - 不止一个,用逗号分隔',
:)