Facebook Platform LogoFacebook recently released the Facebook Platform which allows developers to write applications and tools that run inside users’ profiles and within Facebook itself. So far, the Platform has been a huge success. Dozens of useful applications are coming out every day and most users are very excited for the extra functionality.

I am in the process of writing an application that brings together Flickr sets and Facebook photo albums. Unfortunately, the current implementation of the Facebook Platform lacks the ability to easily upload photos to a user’s account.

To remedy this situation, Paul Wells and I decided to writing our own addition to the Facebook PHP5 Client Library. Using it is as simple as uploading the file to your server and changing two lines of code in your existing applications. The best part is that our class does not involve code hacks at all. Our classes simply extend the current ones and add the functionality we want. The advantage to this approach is that the code will still work if Facebook updates the API.

To download the code and see an example of it’s use, visit the project page.

15 Responses to “Uploading Photos within Facebook Apps”

  1. rob says:

    Hi,

    Thanks for this…I’m a bit new to php (came from java bkgrd). The fb photo lib u provided works well with photo files already up on a webserver…is there a way i can get upload file from my local hd to facebook directly?

    Thanks in advance.

  2. admin says:

    You can’t upload directly from your computer. You need to use an upload form to upload it to your server, and then upload it to Facebook from there.

    Here is a good tutorial on how to do that.

    Good luck!

  3. rob says:

    thanks. I will give that a shot.

    Rob

  4. rob says:

    Hi,

    Another question…FB/PHP related. I was following the http://www.w3schools.com/php/php_file_upload.asp tutorial, and all is well OUTSIDE of Facebook.

    So, when i was inside of facebook, i have normal html form code. When submit is pressed, the filename doesn’t seem to get pass to .php file that actually does the uploading… any idea?

    Thanks again,

    Rob

  5. admin says:

    I’ve never uploaded files using the Facebook Platform, but it shouldn’t be any different. You can try using

    print_r($_REQUEST);

    to see if your file is available anywhere.

    A better place for these type of questions would be the Facebook Developers Group and the discussion board provided there.

  6. Bailey Cross says:

    Thanks for the great library.

    I’m trying to use it with the php4 library and I’m having some trouble with the api_client->users_isAppAdded() function. It appears to fail and I cannot figure out why or what going on. I’m certain the php4 library works fine and your code looks like it extends the class so I’m not sure why would it effect this method.

    Thanks,
    Bailey

  7. admin says:

    We never tested it with the PHP4 library, so I can’t provide any help in that regard. Sorry.

  8. Courtland says:

    When I use the example code provided, it doesn’t upload the image to the specified album. If I don’t specify an album, it creates a new one for my application but still doesn’t upload the image.

    Any idea what could be wrong?

  9. aaron says:

    Hey Guys,

    Great work!

    If I don’t include the following line :

    $albums = $this->facebook->api_client->photos_getAlbums($user, null);

    The photo gets uploaded twice. weird stuff…

  10. Mamboozle says:

    I can’t download it. When I click the download link at the http://wiki.eyermonkey.com/Facebook_Photo_Uploads page it just brings me to this blog. The link in this blog just brings me back to the other page.

    Is there a working sample? Is this going to be easier than setting it up myself?

  11. ahmed says:

    the link doesnt work!!

    would be great, if you could made the zip available again!

    thanks

  12. admin says:

    I apologize for the file being missing for a while. I switched servers and forgot to re-upload it. It’s available for download again.

  13. Scott Phillips says:

    Were you guys going to update this any time soon to work with the new facebook stuff? It doesn’t seem to work @ all even with the code update on the project site.

  14. Carlos says:

    Would be great to have a working version of this function :(
    Anyone out there know how to upload pics to an application’s album?

  15. Ari says:

    thanks for the library - implementation was a breeze!

    i can’t seem to find much information about how the API interacts with FB pages(as opposed to your personal profile). does anyone know if there is a way to upload photos to an FB page (either as an admin or a fan)?

Leave a Reply

Socialized through Gregarious 42