此共享代码不适用于桌面共享,但可以在移动共享中正常工作。在台式机上,我遇到了错误。
function getBase64Image(img) {
var canvas = document.createElement("canvas");
canvas.width = 614;
canvas.height = 1079;
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0);
var dataURL = canvas.toDataURL("image/png");
return dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
}
function fbShare() {
FBInstant.shareAsync(
{
intent: 'SHARE',
image: getBase64Image(document.getElementById('loveimage1')),
text: 'What type of lover are you? Find Out. Share. Win.',
data: {
myReplayData: '...'
}
}).then( function()
{
console.log("sharing is done");
})
.catch( function(err)
{
console.log('failed to share: ' + err.code + " :: " + err.message);
});
};