2010-07-29 56 views
5

我试图将图像上传到我的用户的Facebook墙上,一旦他们打了一个钮FACEBOOK JS SDK ::如何张贴图片上墙

我使用的JavaScript SDK,但我有一个问题,图像看起来像一个在墙上的链接...但这不是我想要的...我想发布一个图像...相同,当你把你的状态文本字段上的图像链接,它变成图像

有帮助吗?

FB.ui(
      { 
      method: 'stream.publish', 
      message: 'test', 
      attachment :{ 
        'name': 'i\'m bursting with joy', 
        'href': ' http://bit.ly/187gO1', 
        'caption': '{*actor*} rated the lolcat 5 stars', 
        'description': 'a funny looking cat', 
        'properties': { 
         'category': { 'text': 'humor', 'href': 'http://bit.ly/KYbaN'}, 
         'ratings': '5 stars' 
        }, 
        'media': [{ 
          'type': 'image', 
          'src': 'http://icanhascheezburger.files.wordpress.com/2009/03/funny-pictures-your-cat-is-bursting-with-joy1.jpg', 
          'href': 'http://bit.ly/187gO1'}] 
         }, 
      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.'); 
      } 
      } 

回答

13

尝试FB.api()方法:

var wallPost = { 
    message : "testing...", 
    picture: "http://url/to/pic.jpg" 
}; 
FB.api('/me/feed', 'post', wallPost , function(response) { 
    if (!response || response.error) { 
    alert('Error occured'); 
    } else { 
    alert('Post ID: ' + response); 
    } 
}); 

你可以得到支持的墙壁post数据here(请参见 “发布”)的列表。

+0

但有没有办法上传图像到用户墙? – trrrrrrm 2010-07-31 11:15:19

+0

@ From.ME.to.YOU很好,图像将作为图标发布到墙上,而不是链接。那是你需要的吗?上传是什么意思? – serg 2010-07-31 15:25:16

+0

@serg嘿,这工作正常,但你能告诉我如何张贴在朋友墙?我想有一个按钮,点击后会“询问”是否将图像张贴到朋友墙上或不是。 – Surya 2012-08-25 14:34:27

12

要在用户墙上发布图片,请使用FB.api('/ me/photos',...)而不是FB.api('/ me/feed',...),并且还需要访问令牌。

附上的代码示例:

FB.login(function(response) { 
    if (response.authResponse) { 
     var access_token = FB.getAuthResponse()['accessToken']; 
     FB.api('/me/photos?access_token='+access_token, 'post', { url: IMAGE_SRC, access_token: access_token }, function(response) { 
      if (!response || response.error) { 
       //alert('Error occured: ' + JSON.stringify(response.error)); 
      } else { 
       //alert('Post ID: ' + response); 
      } 
     }); 
    } else { 
     //console.log('User cancelled login or did not fully authorize.'); 
    } 
}, {scope: 'publish_stream'}); 

张贴在朋友页:就地“/我”的输入朋友的Facebook的用户ID。

"/"+friends_user_id+"/photos" ....