3
votes

I'm using Facebook SDK for Unity 5.1. But I have problems developing Android apps.

See the following:

void GetInviteFriends() {
    FB.API("/me/invitable_friends", Facebook.HttpMethod.GET, FriendCallback); 
}

Facebook Graph API 2.0 has invitable_friends query. It's returned to friends token. (not id)

I have read many manuals, many examples, Q&As but cannot find how to use 'FB.Apprequest : invitable_friends query, Facebook SDK 5.1 for Unity3D'.

Other example(javascript): using FB.ui .. friend token insert 'to' parameter. it's OK.

Facebook SDK for Unity has FB.AppRequest. it gives a useful App Request User to User.

but, FB.AppRequest's to parameter does not read friend token...

or i don't use friend token. my apps is public, and in game category.

it inserts friend token's to parameter result.

400 Bad Request
UnityEngine.Debug:LogError(Object)
FbDebug:Error(String)
Facebook.FallbackData:JSFallback(String)
Facebook.AsyncRequestDialogPost:CallbackWithErrorHandling(FBResult)
Facebook.<Start>c__Iterator0:MoveNext()

i don't know what is the problem.

and this is the external call messages

External Call: fbUi("{\"message\":\"I'm Invite to you.\",\"to\":\"AVnBTaC8ez5yUfksw2oOTepdNOaVkQqTKH2bQ1CW9R4U88MEGDUvtF2C9mclasIBT9am7ADKbIdzq3SXMpWx3dTDcR7oPwV18kzPcKZlSQaoIA\",\"title\":\"Friends to Invite\",\"app_id\":\"1449208528671088\",\"locale\":\"en_US\",\"method\":\"apprequests\"}", "1");
UnityEngine.Application:ExternalCall(String, Object[])
Facebook.CanvasFacebook:JSFallbackUI(String, Dictionary`2, FacebookDelegate)
Facebook.FallbackData:JSFallback(String)
Facebook.AsyncRequestDialogPost:CallbackWithErrorHandling(FBResult)
Facebook.<Start>c__Iterator0:MoveNext()

this is my FB.AppRequest form.

 public static void AppRequest(
        string message,
        OGActionType actionType,
        string objectId,
        string[] to,
        string data = "",
        string title = "",
        FacebookDelegate callback = null)
{
    FacebookImpl.AppRequest(message, actionType, objectId, to, null, null, null, data, title, callback);
}

I used this:

FB.AppRequest(
    DirectRequestMessage,
    null,
    "",
    DirectRequestTo,
    "",
    DirectRequestTitle,
    Callback
);
2

2 Answers

1
votes

The Facebook Unity SDK is still using v1.0 of the graph API. While the documentation seems to indicate that you can call a 2.0 method, it just returns a 400 error as you have seen.

Regardless, even if this did work, you still do not have the correct info from Facebook to use the FB.AppRequest methods that require a userID, since invitable_friends doesnt return user IDs.

Instead of using "me/invitable_friends", you can continue to use "me/friends". This 1.0 method will return the name and ID of all friends.

Facebook is saying that April 30th 2015 they will kill the 1.0 API, but they have yet to provide an alternative.

Sample Code:

public void GetAllFriends()
{
    FB.API("/me/friends", Facebook.HttpMethod.GET, GetAllFriendsDone);
}

private void GetAllFriendsDone(FBResult result)
{
    if (string.IsNullOrEmpty(result.Error) == false)
    {
        UnityEngine.Debug.Log(result.Error);
    }
    else
    {
        UnityEngine.Debug.Log(result.Text);
        //DO something with friends
    }
}
0
votes

Figured out a way through the Friendsmash-unity example how to call the api correctly.

FB.API("/v2.0/me?invitable_friends", Facebook.HttpMethod.GET, InviteCallback);

Really suggest to update your code and implement it this way as the API 1.0 will be pulled soon.