微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用AJAX / jQuery发布到Facebook墙/源

把头发拉过这一个.

我正在编写一个连接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"
});

但我只是不断收到此错误:“XMLHttpRequest无法加载https://graph.facebook.com/bbeckford/feed.Access-Control-Allow-Origin不允许使用Origin http://www.secretsantasetup.com.”

我已经完成了搜索,一个建议是制作一个PHP代理,这是一个可行的选择吗?我该怎么做呢?

我接近这个完全错了吗?

任何帮助将不胜感激,
谢谢,
-ben

编辑
我想在后台执行此操作,例如用户已选择10个朋友,然后在提交时,应用程序将遍历每个朋友并在他们的墙上发布内容.这可能吗?
谢谢!

编辑2
下一页底部的测试控制台正是我想要做的,但是没有源代码? – http://developers.facebook.com/docs/reference/rest/stream.publish

解决方法

在这里,您将使用javaScript SDK

步骤1

首先,您的应用程序应获得在用户墙或用户的朋友墙上发布的权限.

来自Facebook的示例代码link

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'});

需要在用户用户的朋友墙上发布publish_stream.

需要编辑的行:{perms:’read_stream,offline_access’})

要阅读有关其他权限的更多信息:link

第2步

取自facebook JavaScript SDK Pages并调整link

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.');
     }
   }

 );

需要编辑或添加的行:target_id:’输入您的朋友IDS – 不止一个,用逗号分隔’,

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐