facebook js api - HTML5 canvas upload as a photo

2019-09-07 05:11发布

Is there a way to convert an HTML5 canvas to a some sort of an image format so that it can be uploaded to facebook users application album though the js api,

I'm currently successfully uploading an image link to an album with the following function:

FB.api('/me/photos', 'post', { message:'the message', url:imgURL});

1条回答
一纸荒年 Trace。
2楼-- · 2019-09-07 05:58

Yes, there is way to convert HTML5 Canvas to an image. Following javascript function on the Canvas JS element will do this:

toDataURL('image/jpeg', 1.0);

You can have PNG also.

This function will generate a Base64 representation of the canvas image. I am not sure if you can directly give a Base64 string to the Facebook API.

If you can, then it will be great, otherwise you need to save it temporarily on the server and give that URL to the FB API.

查看更多
登录 后发表回答