Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Assuming you want to do this in pure JavaScript/JQuery - you'll need to use an iframe as the target of a form, there is a caveat - you will not be able to use the return data (the ID / success of the call) because of the same origin policy.</p> <p>First create a form that will hold the file input and any other variables you wish to set:</p> <pre><code>&lt;form id="upload-photo-form"&gt; &lt;input name="source" id="source" size="27" type="file" /&gt; &lt;input name="message" id="message" type="text" value="message example please ignore" /&gt; &lt;/form&gt; </code></pre> <p>Here is the main function used which creates an iframe, points the form to use it, and then retrieves the latest photo from the album using FQL.</p> <pre><code>function fileUpload(form, action_url, div_id) { // Create an iframe var iframe = document.createElement("iframe"); iframe.setAttribute('id', "upload_iframe"); iframe.setAttribute('name', "upload_iframe"); iframe.setAttribute('width', "0px"); iframe.setAttribute('height', "0px"); iframe.setAttribute('border', "0"); iframe.setAttribute('style', "width: 0; height: 0; border: none;"); // Add to document. form.parentNode.appendChild(iframe); window.frames['upload_iframe'].name = "upload_iframe"; iframeId = document.getElementById("upload_iframe"); // Add event to detect when upload has finished var eventHandler = function () { if (iframeId.detachEvent) { iframeId.detachEvent("onload", eventHandler); } else { iframeId.removeEventListener("load", eventHandler, false); } setTimeout(function() { try { $('#upload_iframe').remove(); } catch (e) { } }, 100); FB.api({ method: 'fql.query', query: 'SELECT src_big,pid,caption,object_id FROM photo WHERE aid= "' + albumID + '" ORDER BY created DESC LIMIT 1' }, function(response) { console.log(response); } ); } if (iframeId.addEventListener) iframeId.addEventListener('load', eventHandler, true); if (iframeId.attachEvent) iframeId.attachEvent('onload', eventHandler); // Set properties of form... form.setAttribute('target', 'upload_iframe'); form.setAttribute('action', action_url); form.setAttribute('method', 'post'); form.setAttribute('enctype', 'multipart/form-data'); form.setAttribute('encoding', 'multipart/form-data'); // Submit the form... form.submit(); } </code></pre> <p>At runtime you will presumably know the albumObjectID from a previous call, and have the access token from the session object that is returned by login or session onauthchange.</p> <pre><code>var url = 'https://graph.facebook.com/' + albumObjectID + '/photos?access_token=' + accessToken; fileUpload($('#upload-photo-form')[0], url, $('#upload-photo-div')[0]);` </code></pre> <p>Obviously this isn't production code, there are a few things you can do to improve it's reliability (like checking the width, height, caption &amp; tags of the submitted image to the latest image). Checking the latest image before &amp; after the attempted upload etc. </p> <p>PS: Watch out for the albumObjectID vs albumID, they are different however both can be obtained using some simple FQL queries. (eg: <code>SELECT aid, object_id, can_upload, name FROM album WHERE owner = me() AND name = "My Album Name"</code>)</p> <p>Hope this helps.<br /> CameraSchoolDropout</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload