Note that there are some explanatory texts on larger screens.

plurals
  1. POException when uploading photo with Facebook Graph API
    primarykey
    data
    text
    <p>I would like to upload a photo to facebook for a user in the default album for an application. This is described under publishing here: <a href="http://developers.facebook.com/docs/reference/api/photo" rel="nofollow noreferrer">http://developers.facebook.com/docs/reference/api/photo</a></p> <p>The method has been answered here: <a href="https://stackoverflow.com/questions/2964410/how-can-i-upload-photos-to-album-using-facebook-graph-api">How can I upload photos to album using Facebook Graph API</a>. I am using the following:</p> <pre><code>$args = array( 'message' =&gt; 'Photo Caption', 'image' =&gt; '@'.realpath("image.png") ); $data = $facebook-&gt;api('/me/photos', 'post', $args); </code></pre> <p>However I get the exception "(#324) Requires upload file" when I attempt this. I have a valid session and I have the publish_stream and user_photos permissions. I can retrieve data using the API. The image file is definitely valid because it can be loaded with <code>file_get_contents(realpath("image.png"))</code>.</p> <p>I've tried this solution, using curl, which works perfectly: <a href="https://stackoverflow.com/questions/2718610/upload-photo-to-album/2728275#2728275">Upload Photo To Album with Facebook&#39;s Graph API</a></p> <pre><code>$args = array( 'message' =&gt; 'Photo from application', 'pic.png' =&gt; '@'.realpath('pic.png') ); $tok = $session['access_token'] $url = 'http://graph.facebook.com/'.$album_id.'/photos?access_token='.$tok; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $args); $data = curl_exec($ch); </code></pre> <p>Compared with Facebook's PHP SDK curl which looks like this (using the same $args and $url):</p> <pre><code>$ch = curl_init(); $opts = self::$CURL_OPTS; $opts[CURLOPT_POSTFIELDS] = http_build_query($args, null, '&amp;'); $opts[CURLOPT_URL] = $url; curl_setopt_array($ch, $opts); $data= curl_exec($ch); </code></pre> <p>Why doesn't the PHP version work? Looks like the http_build_query() function is interfering with loading the image. I don't know enough about curl to understand what's going on here.</p>
    singulars
    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.
 

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