I’m working on a Facebook application that allows people be able to upload their photo through the app and then if they click on ‘Make Facebook Profile Picture’ button, their Facebook profile picture will be changed automatically.
Actually, it is not possible to change the profile picture directly via Facebook Photo Graph API as no section mention about that.
However, we can do a trick by uploading user’s photo to Facebook via the API then redirect the user to uploaded photo URL with 1 added in querystring parameter as below:
“&makeprofile=1” is the main thing here and xyz/abc will be returned by Facebook. By adding the parameter, Facebook will auto change the profile picture of the current user with the uploaded picture above.
PHP change Facebook profile picture
I assume that we already have an image on your server. In real case, we can download/save an external image via url or from user uploading. Our job is just upload it to Facebook then redirect to the uploaded photo url with “makeprofile=1” parameter.
In the example above, we will upload a photo to the “Profile Pictures” album of user and it’s my recommendation as it may doesn’t work if you try to create a new album then upload photo to there.
- 1. In order to upload to Facebook, we need to add 2 settings: cookie = true and fileUpload = true (line: 10,11) and don’t forget to replace appId and secret with yours.
- 2. The whole process may take a moment depend on how big the uploaded photo is.
- 3. The process can’t be completed if user close the browser at the time we redirect to Facebook (Photo page). It just completes when the user be redirected from Photo page to their Wall page.