-
-
Save rams502/84d149d69c0867b1eb91b7fe64a972f5 to your computer and use it in GitHub Desktop.
Revisions
-
hnagata created this gist
Mar 11, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ /* * Code snippet to post a HTML5 Canvas image to Facebook * H. Nagata * * Variables: * accessToken: Facebook access token * targetID: Posting target id such as user id or album id * canvas: HTMLCanvasElement * base64.decode: c.f. https://github.com/hnagata/js-base64 * * It won't work in IE9 since using ArrayBuffer/FormData/Blob. */ // Convert canvas into binary data var data_url = canvas.toDataURL(); var mime = data_url.slice(data_url.indexOf(":") + 1, data_url.indexOf(";")); var data = base64.decode(data_url.slice(data_url.indexOf(",") + 1)); // Construct FormData var fd = new FormData(); fd.append("access_token", accessToken); fd.append("source", new Blob([data], {type: mime})); // And append some fields, such as "message" and "privacy" // POST var req = new XMLHttpRequest(); req.open("POST", "https://graph.facebook.com/" + targetID + "/photos"); req.send(fd);