Friday, April 15, 2011

me and my facebook(s) - part 2

Friday evening, at the office, waiting for a server to "get real"...it won't
Anyway, the last weeks I had to do some stuff with the new Facebook API (which is really ok, I suppose...only it is not documented in a very efficient manner, so I end up spending hours for some simple tasks).

So, 2 easy hints if you want to upload a picture with the API (you will find tones of examples of code of how-to, the actual algorithm, using a PHP library which wraps the requests in a more elegant way, or directly with CURL):
1.For upload need special permissions - main permissions: read_stream, publish_stream, photo_upload, user_photos
2. Before the upload code you need to set the upload file support
$facebook->setFileUploadSupport(true); 
Now, some other things I had to do were 1. to save a picture (from the disk) to a Facebook user Profile album and 2. eventually open it so the user has the possibility to set it as his/her Profile Picture. The first thing is possible if the user already has a Profile Picture album. Otherwise you can not create from API that type of album (with type = 'profile' ). If the user did not have a profile picture yet it will be saved in an album with the application name.
The second part is alittle tricky, because Facebook would not allow an application to mess around with stuff which is part of user's privacy - such as the profile picture, so all you can do is open a new window with the saved picture in Facebook and let the user decide if he/she wants that picture to be his/her profile picture. How to do that? The action of saving a picture to profile/or_not_profile_yet album will return you the ID of the picture (in the Facebook graph), say it's $pid. The url where the user can see the picture and take the decision I've talked above looks something like this:

http://www.facebook.com/photo.php?fbid=$pid&makeprofile=1

No comments: