Search code examples
facebookfacebook-graph-apiunity-game-enginefacebook-unity-sdkfacebook-app-requests

Unity Facebook SDK: AppRequest Error 400 Bad Request


i've been building a social manager class for use with the facebook unity sdk, not the prime[31] version, just the one you can get from facebook: https://developers.facebook.com/docs/unity/downloads

I'm building this for use with both Android and IOS in mind using the Unity3D engine.

Everything went pretty smooth until i tried to implement App-request with the manager.

I get an "Error 400 bad request" without much to on except the error message, so i was hoping anyone here might be able to help me figure this out:

The code that calls the app request:

void RequestAskfor(string requestTitle, string requestMessage, string objectID, string Quantity)
{
    string[] friendIDs = new string[CurrentUser.FriendList.Count];

    for (int i = 0; i < friendIDs.Length; i++)
    {
        friendIDs[i] = CurrentUser.FriendList[i].UserID;
    }

    string data = "{\"type\":\"AskFor\",\"item\":\"{\"objectID\":\"" + objectID + ",\"quantity\":\"" + Quantity + "}}";

    FB.AppRequest(requestMessage, Facebook.OGActionType.AskFor, objectID, null, null, null, data, requestTitle, RequestCallback);
}

And this is the gui button that is supposed to test if it works:

if(GUI.Button(new Rect(300, 300, 300, 300), "Apprequest Test"))
{
    RequestAskfor("Giv mig mad", "Giiiiv miiiig maaaaaad", "food", "1");
}

Here is my permissions that i used to authenticate the app with:

if (GUI.Button(new Rect(100, 200, 125, 35), "Login!"))
{
    Login("email,publish_actions,public_profile,user_friends,invitable_friends");
}

All of the code above works (to an extent) and i am even able to get the "invite request screen"

However when i press okay on the invite request screen i get this error message and an external call from the API:

Error Message:

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

External Call: (a little too big for format properly)

    External Call: fbUi("{\"message\":\"Giiiiv 
    miiiigmaaaaaad\",\"action_type\":\"askfor\",\"   
    object_id\":\"food\",\"data\":\"{\\\"type\\\":\\\"AskFor\\\",\\\"item\\\":\\\"
    {\\\"objectID\\\":\\\"food,\\\"quantity\\\":\\\"1}}\",\"title\":\"Giv mig 
    mad\",\"app_id\":\"339275729572840\",\"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()

If you want to take a closer look at the code here's a link to the only two scripts in the project: https://www.dropbox.com/s/5htdry9gd4bhwip/SocialManager.zip?dl=0

I've been checking up on the documentation of the FB.AppRequest method, and have tried to find people with a similar problem, but so far i haven't been able to solve this problem (obviously).

All the other code works fine however, it's just the AppRequests that are bugging me out at the moment.

It should probably also be mentioned that this code is not finished and looks a big sloppy. But thanks in advance, for any help you guys can give me!


Solution

  • The object ID must refer to an actual OpenGraph object (usually a numerical ID). Here's how you create them.

    https://developers.facebook.com/docs/games/requests/v2.1#creatingobject