I am using the JavaScript SDK to create an app that lists the users attending a public event. Everything works great when the user is logged in, but I get errors when trying to view the data without being logged in (because there is no access token).
How can I securely generate an access token for the purpose of displaying Event Details without being logged in? I know it can be done server-side with PHP SDK, but I'd rather stick to JavaScript for my purposes unless I have no other choice. Thanks for any replies!
window.fbAsyncInit = function() {
FB.init({
appId : '{my-app-id}',
status : true,
xfbml : false
});
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// the user is logged in and has authenticated your
// app, and response.authResponse supplies
// the user's ID, a valid access token, a signed
// request, and the time the access token
// and signed request each expire
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
setupApp();
alert('Connected');
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook,
// but has not authenticated your app
alert('Not authenticated.');
} else {
// the user isn't logged in to Facebook.
alert('Not logged in.');
}
}); // end getLoginStatus
function FBLogin() {
//console.log('login');
FB.login(function (response) {
if (response.authResponse) {
alert('wooooohoo');
}
}, {
scope: 'rsvp_event,publish_stream,offline_access,friends_events'
});
}}; // end Init