Change Facebook Cover or Profile Pic with PHP
I have seen people making separate souvenir page on their websites, where they put some wonderful wallpapers, mini e-card or freewares, something to remember them by. But now times are changing with Facebook trend, so why not add some cool custom made Facebook cover images for your visitors? I am sure it will surely increase some visibility of your website on Facebook.
Few weeks ago someone sent me a mail asking if I could write a simple PHP script that will change Facebook profile cover or profile picture automatically using Facebook API. So, I explored possibilities in API References but there’s none, not yet! (let me know if they allow this in future) But later found out that with little trick Facebook cover or Profile image can be changed. The trick is to upload picture in user’s Facebook account and redirect user to his/her Facebook profile page, where s/he just has to click save changes button.
We will need Facebook Application ID and Secret, jQuery and Facebook PHP SDK files from Github.com (included in sample download file). I have created two PHP files, index.php and process.php. Index.php just lists the Facebook cover images, when user clicks on an image, it will redirect him to process.php page, and then user can decide if s/he wants to make image cover or profile pic.
Cover Pictures List
First page where user finds all the wonderful cover images, and clicks the one he likes for his/her Facebook profile. To make it little interesting I have also created a small css file, which is included in sample file, and included jQuery for the fade effects on the cover images. You can create a similar page with some images, each image linking to process.php.
This is main page which does the task of posting cover picture on user’s Facebook account. Once the image is posted, picture can be set as cover or profile picture.
Permissions: To post pictures to user’s wall, your application requires publish_stream permission, and to access user photos user_photos permission is required. Without these Facebook permissions, your application can not post or access user photos. So we make sure our application have appropriate Facebook permissions before trying to change user cover or profile picture.
Saran Chamling. (He loves the web technology, and enjoys designing, exploring and writing about it @saaraan.com).