How to upload Facebook Cover Photo to Facebook via Javascript

Upload Facebook Covers to Facebook using JavaScript is possible, this is the script:

<?php 
$url= $_GET['url']; 
?>
 <html xmlns="http://www.w3.org/1999/xhtml"
 xmlns:fb="https://www.facebook.com/2008/fbml">
 <head>
 <title>Upload Facebook Covers to Facebook via Javascript</title>
 <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
 </head>
 <body>
 <div id='fb-root'></div>
 <script src='http://connect.facebook.net/en_US/all.js'></script>
 <p id='msg'></p>
<script type="text/javascript">
FB.init({appId: "xxxxxxxxx", status: true, cookie: true})function Login() {
 FB.login(function(response) {
 if (response.authResponse) {
 var access_token = FB.getAuthResponse()['accessToken'];
 console.log('Access Token = '+ access_token);
 FB.api('me/photos', 'post', {
 message: 'http://socialdevelopers.wordpress.com/',
 status: 'success',
 access_token: access_token,
 url: '<?php echo $url; ?>' 
 }, function (response) {
if (!response || response.error) {
 alert('Error occured:' + response);
 } else {
 alert('Cover uploaded');
 }
});
 } else {
 console.log('User cancelled login or did not fully authorize.');
 }
 }, {scope: 'user_photos,photo_upload,offline_access,publish_actions,email,read_stream,publish_stream,user_birthday,user_location,user_hometown,friends_birthday,friends_location'});
};
</script>
 <a href="#" onclick="Login();">upload to facebook</a>
</body>
</html>

Now that just type in the URL of your site followed by the name of the image file and you’re done!

For example: http://socialdevelopers.wordpress.com/upload.php?url=image.jpg

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s