Upload photo to Facebook graph API - an unknown error has occured RRS feed

  • Question

  • Ok so I need a bit of help. This is what im doing so far.

    I have used the Web Authentication broker example to pull my Access token for facebook (of course I added the 'publish_stream' scope to ensure I can post), and save it in localsettings as such:

    function callbackFacebookWebAuth(result) {
            var url = result.responseData;
            var param1 = url.split("&");
            var param2 = param1[0].split("=");
            localSettings.values["Facebook.AccessToken"] = param2[1];

    This works fine. Success.

    Then, I am attempting  to upload a picture as such:

    var accessToken = localSettings.values["Facebook.AccessToken"];
                var blob = canvas.toDataURL('multipart/form-data');
                var filename = "photo.jpg";
                var data = new FormData();
                data.append("access_token", accessToken);
                data.append("message", "test");
                data.append("source\"; filename=\"" + filename + "\"", blob);
                    type: "POST",
                    url: "https://graph.facebook.com/me/photos?access_token=" + accessToken,
                    data: data,
                }).then(function (response) {
                }, function (errorResponse) {
                    var result = JSON.parse(errorResponse.responseText);

    The code seems like it should work. I have tested this by posting text only to /feed and it works. However when posting to /photos I run into issues.

    I have converted the Canvas content to a dataUrl ('multipart/form-data' as suggested for this POST command)

    I use the hack that Synergist suggested in this thread: http://social.msdn.microsoft.com/Forums/en-US/winappswithhtml5/thread/0d23db45-afea-4886-b3ca-522a6919c9f7

    However  I get the following Error:

    (#1) An unknown error occurred

    So now I'm stuck.

    I've googled all day to no avail, so I am reaching out to the community for help. Can someone take a look at the code and tell me what I might be doing wrong??

    Would much appreciate it!

    • Edited by kmrastegar Friday, November 23, 2012 9:01 AM
    Thursday, November 22, 2012 12:34 PM


  • OK I fixed it guys; here is how.

    instead of:

    var blob = canvas.toDataURL('multipart/form-data');
    I used
    var blob = canvas.msToBlob();
    Success!! Hope this helps other people.
    • Marked as answer by kmrastegar Sunday, November 25, 2012 8:36 AM
    Sunday, November 25, 2012 8:36 AM