Question

Given the following call to post an action on an object, what is the code to determine whether a user has taken the action for said object? Switching "post" to "get" pulls all the user's actions (not just for the current obj), and replacing the first argument with the object's URL throws an error.

  • Clarification: I want to know if the user took the action yesterday, or at some previous time. Not whether or not a current call is successful.

            FB.api('/me/namespace:action', 'post', likeOpts, 
            function(response) {
                if (!response || response.error) {
                    console.log(response.error);
                } else {
                    // success
                }
            });
    
Was it helpful?

Solution 3

The scope of my intended question has changed, so this answer isn't 100% direct, but it's what I ended up using, and I think it could benefit future viewers.

I use the following FQL query via the js sdk in order to find out if a specific user has liked a specific object. If they have, it will return an array with their id. If they haven't, it will return an empty array:

        FB.api({
            method: 'fql.query',
            query: 'select user_id from like where user_id=' + UserIDVar + ' and object_id=' + ActionIDVar,
            return_ssl_resources: 1
        }, function(response){
            console.log(response);
        });

The FQL query can be modified to suit your needs, and the documentation can be referenced here: https://developers.facebook.com/docs/reference/fql/like/

OTHER TIPS

It should show up in their feed- you can check the user's feed if they've given you the access token for using the app. I did a test w/ open graph to test just that, but since it was me, I could check my own feed. With another user, you'd have to capture the access token before it expires, and populate it in the FB graph explorer tool.

There is no such call to accomplish this.

You should be saving the previous actions to your database (or saving a boolean that the user already made an action) or checking the last previous action within the get response of /me/namespace:action. From within that response you can filter for the current object url.

If it was a read action you would get an error when making the user call the action twice.

If the action returns an action instance id, the call is successful and save it.

FB.api(
'/me/namespace:action',
'post',
{ OBJECT_TYPE: 'OBJECT_URL' },
function(response) {
   if (!response || response.error) {
      alert('Error occured');
      console.log(response.error);
   } else {
      alert('Code was successful! Action ID: ' + response.id);
   }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top