How to see if a user likes my javascript page or not?

Asked

Viewed 25 times

-1

I was impressed not to find this question in similar questions. The fact, however, is that I have already found this question several times in English on this site, and none of the solutions presented solved my problem. Maybe because these questions I found in English are old, and facebook lives updating ways to use facebook javascript SDK. I want to know how today I do to know whether or not a certain user likes my facebook page JS SDK. I’m tired of looking for the solution on the internet and nothing works. My code for it doesn’t work. Here’s the code:

$(document).ready( function () {
        try {
            FB.init({
                appId  : '{meu_ap_id}',
                status : true, // check login status
                cookie : true, // enable cookies to allow the server to access the session
                version: 'v5.0'
            });
        } catch (e) {
            alert(e.message);
        }
        FB.getLoginStatus(function(response) {
            if (response['status'] == 'connected') {
                token = response['authResponse']['accessToken'];
                FB.api('/me/likes/{page-id}', 'get', {access_token: token} function(result) {
                    alert(result);
                    if (result){ 
                        alert('is fan');
                    } else alert ('not a fan');
                }); */
            }
        });

    });

The init() works. getLoginStatus() also works by returning 'Connected' (this after I have saved in my application’s configuration the url of my site as a valid redirection url to Oauth2. But FB.api(), as exposed in the code does not work. Can anyone tell what is wrong in my FB.api(), or also in another part of the code? For example: the Alert(result) I put inside the callback function to test the code does not run, implying that everything within FB.api does not run. From now on, thank you.

  • I want to say that I’ve already found two syntax errors in this code. Well. now the code only returns "is fan", even though I haven’t liked the page.

  • better read the documentation of the Facebook api, there it is updated and even in Portuguese: https://developers.facebook.com/docs/graph-api/reference/v6.0/object/likes

1 answer

0

Ricardo Pontual, I read the documentation and applied the change. Replace my FB.api with the suggested code on the page you gave me:

FB.api(
                            "/340029920105070/likes", {access_token: '{app_id|{o resto do token}'},
                            function (response) {
                              alert(response.error.message);
                              if (response && !response.error) {
                                alert('sss');
                              }
                            }
                        );

However, the suggested code on the page did not come with the access_token, which caused Alert(Response.error.message) to return an error saying I would need an app_secret or an app token. I spent all day working on it, until I seem to have solved the problem, but another problem arose, namely: "(#10) This endpoint requires the 'manage_pages' permission or the 'Page Public Content Access' Feature. Refer to https://developers.facebook.com/docs/apps/review/login-permissions#Manage-pages and https://developers.facebook.com/docs/apps/review/feature#Reference-PAGES_ACCCESS for Details.". I’ll even take a look at these suggested links, but if you or someone else has a solution to this problem, I’d like you to bring it to me, because I’ve been trying to solve this problem for many days. Grateful.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.