3

我已经动态创建了一个 html 画布图像。我想通过 javascript sdk 将它发布到 facebook 用户的墙上。我正在做的是

我试图将画布转换为 javascript 图像对象并在 fb.ui 方法中提供 finalimage

var temp = canvas.toDataURL("image/png"); 
var finalimage=temp.replace(/^data:image\/(png|jpg);base64,/, "");

  FB.ui(
  {
   method: 'feed',
   name: 'The Facebook SDK for Javascript',
   caption: 'Bringing Facebook to the desktop and mobile web',
   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.'
   ),
 link: 'https://developers.facebook.com/docs/reference/javascript/',
 picture: finalimage
   },
  function(response) {
  if (response && response.post_id) {
  alert('Post was published.');
  } else {
  alert('Post was not published.');
  }
  }
   );

但我收到一个错误

错误消息:图片 URL 格式不正确

谁能帮我怎么做?

4

1 回答 1

0

You need to save the image at your server for doing that, your image must be outside Facebook, because FB.ui "FEED" does not accept base64 encoded data as picture, its impossible .

Its very large data, and if you try to short the base64 code into a url shorteer, you will find difficulties too .

What you can do, and what i am doing, is use an PHP server to get the Base64 data, and convert it into image, like a dynamic image, ok? But a memory problem will be created .

Another option is (really) posting the canvas as an image on user profile, so you will need use FB.api for that, instead of FB.ui, feed dialog is used for sharing links, and, canvas doesnt have Title, Description, proprieties .

After posting the image, you will get an response, with ID, that is post ID, and this cannot be used on Feed as Link or Image proprietity, but you can use Share Dialog, if you want to share the post .

That is piece of cake, i done that, and recommend you do the same . Posting Canvas as images usin API on Facebook Platform is great, you can do that using JavaScript SDK .

于 2016-01-02T19:33:31.317 回答