Reputation: 399
How do I like a Facebook business page once the user has logged in and authorized my app to Publish on his/her behalf? Here's my code so far:
window.fbAsyncInit = function() {
FB.init({ appId: 'MY_APP_ID',
status: true,
cookie: true,
xfbml: true,
oauth: true});
document.getElementById('fb-auth').addEventListener('click', function() {
FB.login(function(response){
if(response.authResponse){ // user has authorized app
FB.api('/me/likes/BUS_PAGE_ID', function(response){
if(response.data.length>0) {
// user has liked the page
} else {
// like the page for the user
}
});
}
}, {scope:'publish_actions, user_likes'});
}, false);
};
The code is working to the point that it authorizes the app and I can see if the business page is liked by the user with FB.api(...) if(response.data.length>0). What do I put in the place of // like the page for the user so that my app can like a specific business page and add it to the user's likes? Thank you.
Upvotes: 1
Views: 2421