Green_qaue
Green_qaue

Reputation: 3661

Creating Facebook Game Requests using LibGdx

I am using Tom Grill's gdx-facebook extension to integrate Facebook in my game, and it works great.

However I cannot find a method to create a Game Request. I can get a list of invitable friends, but that is only useful if you want to create a custom list, and only returns a fraction of your friends.

I want to get all friends, and be able to send them a game request, is it possible? If it is, how do I get a list of all friends and how do I send them game requests?

Sources:

FB-dev: https://developers.facebook.com/docs/games/services/gamerequests

Extension: https://github.com/TomGrill/gdx-facebook

Example using extension: https://github.com/TomGrill/gdx-facebook-app

Upvotes: 1

Views: 298

Answers (1)

TomGrill Games
TomGrill Games

Reputation: 1593

Getting all invitable friends goes like this:

This only works when your Facebook app is a Game.

GDXFacebookGraphRequest request = new GDXFacebookGraphRequest().setNode("me/invitable_friends").useCurrentAccessToken();

This will give you a list of 25 friends, who are not connected with the your app. To gain the hole list you have to use "paging".

The JsonResult contains a list of friends and at the end the paging information. Looks like this:

{
"data": [
    {
        "id": "AVlH4xqLBxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "name": "Friends Name",
        "picture": {
            "data": {
                "is_silhouette": false,
                "url": "https://scontent.xx.fbcdn.net/v/t1.0-1/pxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
            }
        }
    },
    .................
],
"paging": {
    "cursors": {
        "before": "QVZAuZATBxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "after": "QVZAtbmxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    },
    "previous": "https://graph.facebook.com/v2.6/12xxxxxxxxxxxxxx/invitable_friends?access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxx&limit=25&after=QVZAuZxxxxxxxxxxxxxxx"
}
}

To get the next 25 friends you have to send another request like this:

GDXFacebookGraphRequest request = new GDXFacebookGraphRequest().setNode("me/invitable_friends").useCurrentAccessToken();
request.putField("after", "QVZAtbmxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");

There is an undocumented field called "limit" which seems to allow you to gain more friends with one request. Be aware this might be changed/removed without notice by Facebook.

request.putField("limit", "1000");

GameRequest:

https://github.com/TomGrill/gdx-facebook/wiki/7.-Game-Requests

GDXFacebookGameRequest request = new GDXFacebookGameRequest();
request.setMessage("Come on play this game with me!");
Array<String> recipientIds = new Array<String>();
recipientIds.add("AVlH4xqLBxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
request.setRecipients(recipientIds);
gdxFacebook.gameRequest(request);

Upvotes: 2

Related Questions