Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to change Facebook profile picture

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 2.59k
    Comment on it

    If you would like to change your facebook profile picture with php or jquery. You can use below code for the same.

    Please download facebook.js from Facebook SDK.

    <script src="//code.jquery.com/jquery-latest.min.js"></script>
    <script src="//connect.facebook.net/en_US/all.js"></script>
    <script src="<?= BASE_URL ?>/js/facebook.js"></script>
    
    // Additional JS functions here
        window.fbAsyncInit = function () {
            FB.init({
                appId: fbAppId, // App ID
                status: true, // check login status
                cookie: true, // enable cookies to allow the
                // server to access the session
                xfbml: true, // parse page for xfbml or html5
                // social plugins like login button below
                version: 'v2.0', // Specify an API version                   
            });
    
            // Put additional init code here
            FB.login(function (response) {
                if (response.status === 'connected') {
                    console.info(response.authResponse);
                    //alert("Your UID is " + response.authResponse.userID);
                    // getFBData();
                    UploadPicture(response.authResponse.userID);
                    $('#fb_id').val(response.authResponse.userID);          
    
                }
            }, {scope: 'publish_actions,user_hometown,user_location,user_photos,user_videos'});
        };
    
        // Load the SDK Asynchronously
        (function (d, s, id) {
            var js, fjs = d.getElementsByTagName(s)[0];
            if (d.getElementById(id)) {
                return;
            }
            js = d.createElement(s);
            js.id = id;
            js.src = "//connect.facebook.net/en_US/sdk.js";
            fjs.parentNode.insertBefore(js, fjs);
        }(document, 'script', 'facebook-jssdk'));
    
        function getFBData() {
            FB.api('/me', function (data) {
                // alert(data.first_name + data.last_name + data.id);
            })
        }
    
     function UploadPicture(userid) {
            flag = false;
            var user_id = userid;
            var imgURL = "http://www.hdwallpapersimages.com/wp-content/uploads/2014/01/Winter-Tiger-Wild-Cat-Images.jpg";
    
            //change with your external photo url
            FB.api('/me/photos', 'post', {
                message: 'photo description',
                url: imgURL
            }, function (response) {
    
                console.info(response);
                if (!response || response.error) {
                    console.info(response.error)
                    return flag;
                } else {
                    console.info(response);
                    top.location.href = 'https://www.facebook.com/photo.php?fbid=' + response.id + '&amp;makeprofile=1';
    
                }
    
            });
        }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: