0

Ok I'm stuck, I want to create an event in facebook, using javascript facebook api, and I want to load an image on the event cover. I can not figure out how I can do it.

I create an image in a canvas and I can upload to facebook using an sendAsBinnary function from: https://stackoverflow.com/a/5303242/945521 And this function

Facebook.prototype.postImageToFacebook = function(authToken, filename, mimeType, imageData, message){
    try {
        showMessage("Creating post...");
        // this is the multipart/form-data boundary we'll use
        var boundary = '----------RaNdOm_crAPP' + getBoundary();
        // let's encode our image file, which is contained in the var
        var formData = '--' + boundary + '\r\n';
        formData += 'Content-Disposition: form-data; name="source"; filename="' + filename + '"\r\n';
        formData += 'Content-Type: ' + mimeType + '\r\n\r\n';
        for (var i = 0; i < imageData.length; ++i)
        {
            formData += String.fromCharCode(imageData[ i ] & 0xff);
        }
        formData += '\r\n';
        formData += '--' + boundary + '\r\n';
        formData += 'Content-Disposition: form-data; name="message"\r\n\r\n';
        formData += message + '\r\n';
        formData += '--' + boundary + '--\r\n';
        //var xhr = new XMLHttpRequest();
        var xhr = null;
        if (window.XDomainRequest) {
            xhr = new XDomainRequest();
        }
        else if (window.XMLHttpRequest) {
            xhr = new XMLHttpRequest();
        }
        else {
            xhr = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xhr.onload = function() {
            window.alert("The photo was published successfully!!");
        };
        showMessage("Sending request...");
        xhr.open("POST", "https://graph.facebook.com/me/photos?access_token=" + authToken, true);
        if (xhr.setRequestHeader)
            xhr.setRequestHeader("Content-Type", "multipart/form-data; boundary=" + boundary);
        xhr.sendAsBinary(formData);

    } catch (ex) {
        stopWaitingSpin();
        debugLog(ex);
    }

};

and with this

 FB.api("/me/events", "POST", {
        "name": name,
        "start_time": start_time,
        //"end_time":end_time,
        "description": description,
        "location": location,
        //"location_id":location_id,
        "privacy_type": privacy_type
    },
    function(response) { 
      if (response && !response.error) {
         var event_id = response.id;
         console.log(response);
      }
    });

I can create a event.

But what need to call to send the image to the cover on event???

Thank's to all

Community
  • 1
  • 1
Natalia
  • 470
  • 2
  • 5
  • 12

1 Answers1

0

Actually its nowhere mentioned in the documentation yet, but to publish a cover photo on an event you need to call \POST /{event-id} with param cover_url:

{event-id} could be obtained as a result when you created an event.

FB.api("/{event-id}", "POST", {
   cover_url: {image-url}
},
function(response) { 
   console.log(response);  // you'll get the response as 'true' or 'false'
});
Sahil Mittal
  • 20,697
  • 12
  • 65
  • 90
  • I had given up, and leave the project for a few months. when I have some free time, I will try what you tell me. Thank you very much! – Natalia Jul 17 '14 at 13:35