Reputation: 59
I am using var userID = (FB.getAuthResponse() || {}).userID;
to get ID of logged in user, FB .init is initialized properly.
The issue that I am encountering is If I put
var userID = (FB.getAuthResponse() || {}).userID;
inside document.ready();
it is returned as undefined whereas if I put it in some javascript function and call that function on a button click, it works perfectly fine.
Anyone know what could be the issue?
I am also getting this when I try to access it directly on my website:
XMLHttpRequest cannot load {CALL o be MADE}. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '{MY WEBSITE ADDRESS}' is therefore not allowed access. (index)
PS: I don't get the above mentioned error in my facebook page tab, I only get this when I try to access directly my website.
Upvotes: 0
Views: 365
Reputation: 74004
I suggest using the asynchronous way to check if a user is logged in and to get his id:
You should never use this method at page load time. Generally, it is safer to use FB.getLoginStatus if you are unsure.
Check out the Facebook docs for code and information: https://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus
Of course you should call this right after FB.init.
Upvotes: 1