Check if user is logged in New Facebook API -
Well, I'm new to Facebook API stuff, and just recently someone told me that I am the old API Was using.
So now, I do not have to figure out how the user is logged in to my site with the new API.
All I really have is
& lt; Div id = "fb-root" & gt; & Lt; / Div & gt; & Lt; Script src = "http://connect.facebook.net/en_US/all.js" & gt; & Lt; / Script & gt; & Lt; Script & gt; FB.init ({appId: '(API)', status: true, cookie: true, xfbml: true}); FB.Event.subscribe ('auth.sessionChange', function (feedback) {if (response.session) {// user is logged in, and a new cookie has been saved) Other {// user logs Out, and the cookie has been cleaned}}); & Lt; / Script & gt;
and a login button.
If someone can show me how anyone logs in, (or is he there?) Because I like it to welcome the user
& Lt; Div id = "fbuser" & gt; To change the login button located in a div named
Or even if you can point me to some useful tutorials, it would be great!
Thanks
Here's an example where fbLoginStatus ()
function will automatically be called when the user logs in / logs out, you can decide which div will appear there.
& lt; Body & gt; & Lt; Div id = "fb-root" & gt; & Lt; / Div & gt; & Lt; Script & gt; Function fbLoginStatus (response) {if (response.status === 'connected') {// user is logged in, show profile div} Other {// user is not logged in, guest div display}} window.fbAsyncInit = Function () {FB.init ({appId: 'your app id', status: true, cookie: true, xfbml: true}); FB.getLoginStatus (fbLoginStatus); FB.Event.subscribe ('auth.statusChange', fbLoginStatus); }; (Function () {var e = document.createElement ('script'); e.async = true; e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js'; document .getElementById ('FB-root'). AppendChild (e);} ()); & Lt; / Script & gt;
Now if you need to see that the user is currently logged in (for example, click on the button):
if (FB.getSession ()! = Null) {// logged User ID: FB.getSession (). UID} else {// user is not logged in}
Sorry, do not know any good tutorials.
Comments
Post a Comment