I am trying to implement a Facebook log-in feature, where the user clicks the Facebook image, the FB SDK does its thing (logging the user in or asking for permissions, etc.) then afterwards I would like to auto-fill some form fields with the response.
Here is my code:
<script>(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#xfbml=1&appId=[appid]&version=v2.0";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-login-button" data-max-rows="1" data-size="medium" data-onlogin="logFBResponse();" data-show-faces="false" data-auto-logout-link="false"></div>
I added the onlogin="logFBResponse();" and created that JS function, but how do I get the user response object? At the very least I would like the user's name and e-mail address.
Thanks,
Andrew
Just call the facebook APIs and get whatever you wish to in your function logFBResponse(). Just like-
function logFBResponse() {
FB.api('/me', function(response) {
alert('Yo ' + response.name + '!');
});
}
To get the email, you need to add scope parameter in the login button, eg: scope="email"
Relevant documentations you can go through-
Using Graph API
Graph API Reference
Related
I'm trying to embed a facebook event on my website. I got the code from facebook with the 'embed event' button, but it keeps throwing errors: Invalid App Id: Must be a number or numeric string representing the application id., FB.getLoginStatus() called before calling FB.init(). and This Facebook post is no longer available. It may have been removed or the privacy settings of the post may have changed.
This is the code:
<div id="fb-root">
</div>
<script>(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/all.js#xfbml=1"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-post" data-href="#" data-width="466">
<div class="fb-xfbml-parse-ignore">
Post
by
User.
</div>
</div>
Note: I replaced all href's with "#" for the sake of my privacy :P
If your website is based on a Wordpress installation please double check your post page source code. If the <script> tag was stripped probably it's caused by the user's permissions. Try to embed a facebook post as Wordpress administrator and it'll work. In my case that was the stupid problem...
I would like to send private message to multiple people using FB API, but I want it to received by the recipients individually not as group message, this is the code given by fb:
<div id="fb-root"></div>
<script>(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/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-send" data-href="http://developers.facebook.com/docs/plugins/" data-colorscheme="light"></div>
this is how it looks like:
I found this code but it seems outdated or deprecated by fb
FB.ui({
method: 'send',
to: sendUIDs,
name: "xxx",
description:'xxx',
link: 'http://www.mysite.com',
});
what I want to achieve is make a fb message notif to my website users,
any idea guys how to achieve it? is it even possible?
thanks!
I only can do it with images. Send the picture to your self, click on the picture, on the bottom right click on forward. Facebook will show you a list of friends with boxes where you can choose the recipients you want to "Forward in separate messages"
P.S. You make want to take a screen picture of your text in order to "Forward [the message] in separate messages"
I hope it helps.
Currently, the code <div class="fb-like" data-href="https://facebook.com/myappurl" data-send="false" data-width="450" data-show-faces="false"></div>
Only shows the like button if I am logged into Facebook in the browser. How do I get it to display even if the user is logged out?
Like wordpress.org for example...See the bottom left hand corner of the page.
Thanks in advance!
Best,
Alex
The only situation where a like button will not show up (assuming it has been implemented properly) is if the page that is to be liked is a Facebook page that has a restriction placed on it. This includes country and age restrictions. If your Facebook page has a restriction, the user needs to be logged in to Facebook so that the user can be verified as to be allowed to see the like button.
It displays regardless of whether a user is logged in or not. If the user is not logged in and clicks on Like, they get a popup that says
"You must log in to see this page."
Are you sure you're including the fb-root div and the Javascript?
<div id="fb-root"></div>
<script>(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_GB/all.js#xfbml=1&appId=Your-App-ID-HERE";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
Can i have a facebook share button without an app id? I have a facebook page, not an app and no associated app.
i have a div
<div class="fb"></div>
and the js file
$('.op-blackfb').click(postToFeed);
var postToFeed = function() {
var share = {
method: 'feed',
u: 'http://mylink.goes/here'
};
FB.ui(share, function callback(response) {
document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
});
}
This used to work, but now it fails with an error in the popup dialog, i'm guessing after facebook changed the API. Does anyone know a workaround for this? I want to have a custom share button? I have the normal fb share button, but i want to have an image that doesn't break the design.
This works without an app id but has the standard fb button
<script>(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/de_DE/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
<div id="fb-root"></div>
<p id='msg'></p>
<fb:share-button type="button" style="display:inline-block;" share_url="http://my.link/here"></fb:share-button>
Thank you,
How about a modal iframe? You can use facebooks sharer. You can use any button you want to open up the dialog. The problem is that this uses a facebook page, so you have to merge it into you design with some iframe or you must use a popup
https://www.facebook.com/sharer/sharer.php?u=[the-link-you-want-to-share]
Also facebooks documentation is also very well done
https://developers.facebook.com/docs/reference/dialogs/feed/
From https://developers.facebook.com/docs/reference/plugins/like/ I got this script to show the like button in my website
<div id="fb-root"></div>
<script>
(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/fr_FR/all.js#xfbml=1&appId=155899567847";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<div class="fb-like" data-href="http://website.com/project/hello" data-send="false" data-layout="button_count" data-width="100" data-show-faces="false"></div>
I only have the appId and the url, can I check is current user liked my page ?
I looked in google and I found some examples using PageId and I dont know how to get it
PageID is necessary for checking that page is already liked or not from another source. If you are in the same page (your facebook page) it means there is no need to get that id as it will automatically have it from the session or somewhere else.
You can get the PAGE ID by one of the following way,
http://hellboundbloggers.com/2010/07/10/find-facebook-profile-and-page-id/
http://rieglerova.net/how-to-get-a-facebook-fan-page-id/