50

Facebook API v2.0 introduced the invitable_friends edge.

An example response from a GET request to this edge is:

{
  "data": [ 
    {
      "id": "AVkgK9fLFxasdvXNbDV_gYogR6lXa9SKLnH...", 
      "name": "Anita Sujarit", 
      "picture": {
        "data": {
          "is_silhouette": false, 
          "url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn2/t1.0-1/c0.0.50.50/p50x50/1470158_10201991701127909_302023572_t.jpg" 
        }
      }
    }
}

Looking closely at that ID, it's not a normal Facebook user id. Instead it's an Invite Token; this token is passed to the Requests Dialog as a value for the to parameter.

The invite token, returned on each of the friend objects as the value of a field named id, is a unique (per user and per game) string of variable length. The invite token is subject to expiration, and may change between game sessions. It is therefore not advisable to cache these results, or to try to assign them to a given person.

The friends edge now only returns friends already using the app


My problem is that I now have no way to cross-reference which friends I have invited and which have accepted.

Previously, I would have stored a friends id as I sent them an invite, and, at some later point, checked this against a list of friends playing the game, but now this isn't possible for several reasons:

  • The invite token isn't present on the friends edge
    • And it's dynamic anyway
  • The normal user id isn't present on the invitable_friends edge.
  • I could use the user's name as a key, but this isn't unique.

Actual Question: Has anybody devised a way of determining, from users that have been invited, which have accepted that invite please?

Braiam
  • 1
  • 11
  • 47
  • 78
James Webster
  • 31,873
  • 11
  • 70
  • 114
  • 1
    You can use user profile photo that is unique. However, if user changes profile photo, the url will be changed and uniqueness will be lost. – Hüseyin BABAL Jun 27 '14 at 12:34
  • 1
    I talked to someone in the facebook developer page https://www.facebook.com/groups/fbdevelopers/741657279211122/?comment_id=741899122520271. Basically whenever a user logs in you can call GET /{user_id}/apprequests to see their pending requests. Alternatively you can check the status of a request as well. For more info https://developers.facebook.com/docs/games/requests/v2.0 – Sean Dunford Jul 09 '14 at 15:15
  • 1
    "Invites have the same behavior as Requests". from https://developers.facebook.com/docs/games/invitable-friends/v2.3 So what you can do is: Reading all requests In order to read all the requests for a recipient for you can query the graph as shown below using the recipient's USER ACCESS TOKEN. This will return a list of request ids for that user in the app. GET https://graph.facebook.com/me/apprequests?access_token=[USER ACCESS TOKEN] From https://developers.facebook.com/docs/games/requests/v2.3 – Mikael Jun 30 '15 at 06:55
  • Use this link...you working on 2.0 facebook introduce new api .....https://developers.facebook.com/docs/games/invitable-friends/v2.4 – Maulik shah Oct 07 '15 at 05:55
  • @Maulik that's the same link I refer to in the very first line of the question (albeit, it's slightly updated now) – James Webster Oct 07 '15 at 06:09
  • see you use Facebook 2.0 api ....its depricated – Maulik shah Oct 07 '15 at 06:55
  • new api is facebook 2.4 – Maulik shah Oct 07 '15 at 07:12
  • While that's true, the API doesn't seem to have changed much for that edge. I think the problem still exists. – James Webster Oct 07 '15 at 07:43

1 Answers1

1

TLDR: Save the response from the actual invite these friends request

As far as I understood the reference you provided:

You can start requesting invite_tokens which I assume you are already able to do.

As answer you get this per invitable_friend:

{
  "id": "AVlzYTkXshfBqLe58zR9tY5dZ7L0wltTUkWKT0Z5V87zkwv-39...", // Invite Token
  "name": "Guy Cross",
  "picture": {
    "data": {
      "is_silhouette": false,
      "url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn1/t5.0-1/623782_622770420_2109148508_q.jpg"
    }
  }
}

The page mentions earlier how to do requests in general:

FB.ui({method: 'apprequests',
  message: 'YOUR_MESSAGE_HERE',
  to: 'USER_ID, USER_ID, INVITE_TOKEN' // It says invite token
}, function(response){
  console.log(response);
});

Look at the line with to: You can put invite tokens in there.

Now the response looks like this:

{
  request: 'REQUEST_OBJECT_ID'
  to:[array of USER_IDs]
}

There you got your user ids.


If you go further and either need more informations or want to see who accepted, then you have two options:

  • you can check if the user id has authorized the game
  • when the new user logs in, you can ask for all requests for this new user. There you can track who invited him. GET https://graph.facebook.com/me/apprequests?access_token=[USER ACCESS TOKEN]
  • you save all the data (stated in TLDR) and check everytime a new user joins your game, if the new user id is in your list of requests mentioned.

To check who invited him, you can do check the request_object_id with http://graph.facebook.com/{REQUEST_OBJECT_ID}?access_token=USER_ACCESS_TOKEN of the recieving user and the following response will be:

{
  "id": "REQUEST_OBJECT_ID",
  "application": {
    "name": "APP_DISPLAY_NAME",
    "namespace": "APP_NAMESPACE",
    "id": "APP_ID"
  },
  "to": {
    "name": "RECIPIENT_FULL_NAME",
    "id": "RECIPIENT_USER_ID"
  },
  "from": {
    "name": "SENDER_FULL_NAME",
    "id": "SENDER_USER_ID"
  },
  "message": "ATTACHED_MESSAGE",
  "created_time": "2014-01-17T16:39:00+0000"
}

if you go with the user access token from the sender you get this:

{
  "id": "REQUEST_OBJECT_ID",
  "application": {
    "name": "APP_DISPLAY_NAME",
    "namespace": "APP_NAMESPACE",
    "id": "APP_ID"
  },
  "from": {
    "name": "SENDER_FULL_NAME",
    "id": "SENDER_USER_ID"
  },
  "message": "ATTACHED_MESSAGE",
  "created_time": "2014-01-17T16:39:00+0000"
}

To prevent this, you can specify the user id of the recieving user and get the same answer as from the receiver: https://graph.facebook.com/{REQUEST_OBJECT_ID}_{USER_ID}?access_token={APP_ACCESS_TOKEN}

Greaka
  • 735
  • 7
  • 16