简体   繁体   English

Facebook JS-FB.api()仅发布消息,不发布媒体附件

[英]Facebook JS - FB.api() only posts message, not media attachment

I'm trying to post to the active users wall with a mp3 attachment. 我正在尝试将带有mp3附件的活动用户帖子发布到活动用户墙上。 It works fine from Facebook's Test Console (see below), but when I call it from my mobile app, It only posts the message. 它可以从Facebook的测试控制台(见下文)正常工作,但是当我从移动应用程序调用它时,它只会发布消息。 What am I missing here :( 我在这里想念什么:(

Facebook's Test Console: http://developers.facebook.com/docs/reference/rest/stream.publish/ Facebook的测试控制台: http : //developers.facebook.com/docs/reference/rest/stream.publish/

Here is my JS... 这是我的JS ...

Login 登录

            FB.login(
               function(response) {
                  if (response.authResponse) {
                       alert('logged in');
                  } else {
                       alert('not logged in');
                  }
               },{ scope: "email,user_likes,publish_stream,offline_access" } //added offline_access to see if that was the problem
            );

Post to wall with attachment 带附件张贴到墙上

            var attachment = {
                    'message': 'testing',
                    'attachment': {'media': [{
                        'type': 'mp3',
                        'src': 'http://www.looptvandfilm.com/blog/Radiohead%20-%20In%20Rainbows/01%20-%20Radiohead%20-%2015%20Step.MP3',
                        'title': 'Test Title',
                        'artist': 'My Artist',
                        'album': 'My Album' }]}
            };

            FB.api('/me/feed', 'post', attachment, function(response) {
              if (!response || response.error) {
                alert(response.error.message);
              } else {
                alert('Post ID: ' + response.id);
              }
            });
        var attachment = {
                'message': 'testing',
                'source': 'http://www.looptvandfilm.com/blog/Radiohead%20-%20In%20Rainbows/01%20-%20Radiohead%20-%2015%20Step.MP3'
        };

This will post the mp3 to your feed allowing a user to click a play button inline. 这会将mp3发布到您的供稿中,允许用户直接点击播放按钮。 See working example here: http://jsfiddle.net/dmcs/aggJc/1/ 在这里查看工作示例: http : //jsfiddle.net/dmcs/aggJc/1/

As you will note, that when you POST data to the Graph API, the formatting is different than when you GET the same object back. 正如你会注意到,当你POST数据到图形API,格式是当你不同于GET相同的对象回来。 Posting is kinda shorthand notation version and the Getting is the long hand. 发布是一种简写形式,而Getting是一臂之力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM