Looking for a batch script to run on our server (Centos 5, PHP 5.1, MySQL 5.0) to upload photos to Facebook user accounts.
The script would run every ~ 1 min via CRONTAB, check the MySQL database that holds reference to the photos on our server and upload any photos that have not been marked as previously uploaded.
The photos would be uploaded to a specified Album in the User Record. If the Album doesn’t exist, it first gets created. If the album has more pictures than the FB limit (Currently 60?), another Album is created with a sequence number appended.
If the photo is uploaded successfully, the row in the database is marked as uploaded (date/time).
NOTES:
- Please make sure you are 100% sure that you have researched the Facebook API and understand the available programming approaches. A good place to start is with the photo.upload API. http://wiki.developers.facebook.com/index.php/Photos.upload .
- There is NO UI component to this project. This is a batch process that will run on a Centos 5 Server.
- Please indicate what technology/programming language you plan to use. Again, has to be compatible with Facebook API.
While it is possible to call php from a CRON, our server runs PHP as an Apache Module, not CGI, so it is unclear to me if using PHP will work for this project. A discussion I found here: http://www.htmlcenter.com/blog/running-php-scripts-with-cron/
- I am not 100% sure that this can actually be done, so let’s not waste valuable time if it can’t be done. (although there are examples of applications that do this type of thing, for example www.pixelpipe.com)
- Database schema attached.
- Please review and comment on the process flow below.
Thanks
***************************************
While I think there might be some fine tuning to do on the process by you professionals, here’s my hacker’s view:
//Connect to the MYSQL Database
//Query to see if there are any records to process. Eliminate certain kinds of records. Order by User ID and upload time so that we process all the records for a specific user and in the order the photos were submitted
SELECT *
FROM wme_media AS m
INNER JOIN wme_user AS u ON m.user_id = u.id
WHERE m.fb_upload_datetime IS NULL
AND m.media_type = “framed_photo”
AND m.deleted = “0″
AND m.content_type = “image”
AND u.deleted = “0″
AND u.facebook_id IS NOT NULL
ORDER BY m.user_id ASC , upload_datetime ASC
//Loop through the records by user
//Get a list of the users albums from FB
//See if they have an album that matches the one in their user profile wme_user.fb_album
//If not, create an album named [wme_user.fb_album]
//If they have an album, use it as the target for upload
//Use the wme_media.path to get the .jpg file to upload
//Upload the file to FB.
//If no errors:
- Mark wme_media.fb_upload_datetime with Date/Time of upload
- Move to next record for that user_id.
//If errors, handle:
- Might be that number of photos in the album has reached FB maxium. If so, create a new album, i.e. Album – 1, Album – 2, etc. and continue the process
- If other errors, write out info to error.log and skip to next record
//If no more records for the user_id, move to the next user
//If no more records, finish