0
votes

I want to track invites that send from "player_1" to other players to count them and as result give "player_1" some reward. Like in PVZ2.

Ok, Facebook have SDK for Unity3d. Here is API to call App request dialog that allow to invite player:

public static void AppRequest(
        string message,
        string[] to = null,
        string filters = "",
        string[] excludeIds = null,
        int? maxRecipients = null,
        string data = "",
        string title = "",
        FacebookDelegate callback = null)

Facebook doc says something about redirect_url that could be used to track user's that accept indentations: https://developers.facebook.com/docs/reference/dialogs/requests/

But Unity plugin doesn't have this param.

Also doc says that follow:

Requests are only available for games on Facebook.com or iOS and Android apps. Accepting a request from a game will direct the person to the Canvas Page URL of the app that sent the Request. For native mobile apps, accepting the request will direct the person to the app on their device if installed or to the appropriate location (Apple App Store or Google Play) to download the app otherwise.

Game is going to work on mobile devices only. Therefore we don't need to make Facebook Canvas application. Should I implement this Canvas URL script on our website anyway?

Where is the correct place to inject code (server side script) to track Facebook app requests?

UPDATE: Thanks to Bhavesh Vadalia for answer: https://stackoverflow.com/a/21597185/425707 I've decided to not handle friends requests in Canvas App. Here is solution for Facebook SDK 5.0.3:

// Quesry string: "/fql?q=SELECT uid, name, is_app_user, pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND is_app_user = 1";
string q = "/fql?q=SELECT+uid,+name,+is_app_user,+pic_square+FROM+user+WHERE+uid+IN+(SELECT+uid2+FROM+friend+WHERE+uid1+=+me())+AND+is_app_user+=+1";
FB.API(q, Facebook.HttpMethod.GET, friendsResult =>
{
    if (friendsResult.Error != null)
    {
        FbDebug.Error(friendsResult.Error);
    }
    else
    {
        FbDebug.Log(friendsResult.Text);
    }
});
1

1 Answers

4
votes

Here is implement for track code using facebook graph api implement in for my application. hope it also help to you.

I am using facebook 3.6 sdk

private void requestMyAppFacebookFriends(Session session) {
        Request friendsRequest = createRequest(session);
        friendsRequest.setCallback(new Request.Callback() {

            @Override
            public void onCompleted(Response response) {
                List<GraphUser> friends = getResults(response);

                Log.e("RESULT : ", "@"+friends.size());

                for(int i =0;i<friends.size(); i++){

                    GraphUser user = friends.get(i);
                    boolean installed = false;
                    if(user.getProperty("installed") != null){
                        installed = (Boolean) user.getProperty("installed");
                    }
                    if(installed){
                        Log.e("USER NAME", "@"+friends.get(i).getId());
                    }
                }
                // TODO: your code here
            }
        });
        friendsRequest.executeAsync();
    }
 private Request createRequest(Session session) {
        Request request = Request.newGraphPathRequest(session, "me/friends", null);

        Set<String> fields = new HashSet<String>();
        String[] requiredFields = new String[] { "id", "name", "picture","installed" };
        fields.addAll(Arrays.asList(requiredFields));

        Bundle parameters = request.getParameters();
        parameters.putString("fields", TextUtils.join(",", fields));
        request.setParameters(parameters);

        return request;
    }