使用 AJAX/jQuery 发布到 Facebook 墙/提要
把我的头发拉到这个上面。
我正在编写一个与 Facebook 连接的 Web 应用程序,该应用程序最终会将一些任意信息发布到整个过程中选择的朋友墙上。
我现在处于最后阶段,希望发布到墙上会很简单,但我现在花了太长时间试图解决这个问题,所以我希望有人可以帮助我。
我试图像这样使用 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"
});
但我不断收到此错误:“XMLHttpRequest 无法加载 https: //graph.facebook.com/bbeckford/feed。来源http://www.secretsantasetup.com Access-Control-Allow-Origin 不允许。”
我已经进行了搜索,一个建议是制作一个 php 代理,这是一个可行的选择吗?我该怎么做呢?
我的做法完全错误吗?
任何帮助将不胜感激, 谢谢, -本
编辑 我想在后台执行此操作,例如,用户选择了 10 个朋友,然后在提交时应用程序将循环遍历每个朋友并在他们的墙上发布一些内容。这可能吗? 谢谢!
编辑2 下一页底部的测试控制台完全符合我想要的功能,但是没有源代码? - http://developers.facebook.com/docs/reference/rest/stream。发布
pulling my hair out over this one.
I'm writing a Facebook-connected web app that will ultimately post some arbitrary information to the walls of friends that are selected throughout the process.
I'm in the final stages now and was hoping that posting to the walls would be simple, but I've spent far too long trying to figure this out now so I'm hoping someone can help me.
I'm trying to post using ajax like so:
$.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"
});
But I just keep getting this error: "XMLHttpRequest cannot load https://graph.facebook.com/bbeckford/feed. Origin http://www.secretsantasetup.com is not allowed by Access-Control-Allow-Origin."
I've done searches and one suggestion is to make a php proxy, is that a viable option? How would I go about doing that?
Am I approaching this completely wrong??
Any help would be greatly appreciated,
Thanks,
-Ben
EDIT
I want to do this in the background, ie user has selected 10 friends for example, then on submit the app will loop through each friend and post something on their wall. Is this possible?
Thanks!
EDIT 2
The test console at the bottom of the following page does exactly what I want to do, but there is no source code? - http://developers.facebook.com/docs/reference/rest/stream.publish
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在这里,您可以使用 javaScript SDK
第 1 步
首先,您的应用程序应该获得在用户墙或用户朋友墙上发帖的权限。
来自 Facebook 的示例代码:链接
publish_stream 需要在用户或用户的上发布朋友墙。
需要编辑的行:{perms:'read_stream,publish_stream,offline_access'})
要了解有关其他权限的更多信息:链接
第 2 步
取自 facebook JavaScript SDK 页面并进行调整link
需要编辑或添加的行:target_id: '输入您的朋友 IDS - 多个,用逗号分隔',
:)
Here you go using javaScript SDK
STEP 1
At first, your application should obtain the permission for posting on user's wall or user's friends wall.
sample code from Facebook : link
publish_stream is required to post on user's or user's friends wall.
Line which one need to edit : {perms:'read_stream,publish_stream,offline_access'})
To read more about other permissions : link
STEP 2
Taken from facebook JavaScript SDK Pages and tweaked link
Line which one needs to edit or add : target_id: 'ENTER YOU FRIENDS IDS - more than one, seperate by commas',
:)
您无法将 ajax 请求发送到另一个域。
只需使用 facebook JS SDK 并做任何你想做的事。
You cannot send ajax request to the another domain.
Just take facebook JS SDK and do whatever you want.
我不确定我在哪里听到这个,但是:
应该可以,你需要在哪里添加“?callback =?”东西。我不知道为什么会这样。但是,只要它有效,我就会感到高兴。
I'm not sure where did I heard this, but:
Should work, where you need to add "?callback=?" stuff. I do not know why did this work. But, as long as it works, I'll stay happy.
您可能需要在对用户进行身份验证时设置范围(如果您尚未这样做)。
如果您使用 WAMS 进行身份验证,请检查此博客以设置范围 http://blogs.msdn.com/b/azuremobile/archive/2013/11/25/what-s-new-in-azure-mobile -services-1-6-4247.aspx
You may need to set the scope while authenticating the user, (if you haven't done so).
If you authenticated using WAMS, check this blog to set scopes http://blogs.msdn.com/b/azuremobile/archive/2013/11/25/what-s-new-in-azure-mobile-services-1-6-4247.aspx