If you would like to get your profile picture in facebook app. Please user the below code, you can 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>
<script>
// Additional JS functions here
window.fbAsyncInit = function () {
FB.init({
appId: fbAppId, // PUT YOUR FACEBOOK APP ID HERE
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();
$('#fb_id').val(response.authResponse.userID);
getUserPicture(response.authResponse.userID)
// UploadPicture(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 getUserPicture(user_id) {
FB.api(
"/" + user_id + "/picture?type=large&redirect=true",
function (response) {
if (response && !response.error) {
$('#profilepic').attr('src', response.data.url);
$.post("saveimages",
{
url: response.data.url,
fid: user_id
},
function (data, status) {
$('#profilepic').attr('src', data);
});
}
}
);
}
</script>
<img id="profilepic" src="vivek.jpeg">
2 Comment(s)