简体   繁体   中英

Facebook graph API/FB UNITY SDK handling App Requests (send & receive)

First, Here is the link to the original question thread that pertains to my specific request for help: Facebook AppRequest handle on unity3d game

Without reading the above, this will not make sense. So, PLEASE, before you vote that it's unclear, or not relevant, or anything else, look at the above link, read it... then, if you can, then comment. If you cannot, then PLEASE just ignore it. I'd really like to get the answer to my question, but it's extremely frustrating to come back and find it's not visible, because someone wanted to down-vote it. This is my first question on here, and I've tried 5 times now just to have it seen for more than 5 minutes.

My original comment: @Aaron, I appreciate you posting your reply to the above link, as I found it trying to figure out how to do what Nick Mascarenhas is also trying to figure out. I (as an Unity developer) would like to also see a GetRequests type function that returns an array of from UserID's and the Request code that was sent to the user logging in. I'm rather new to the Facebook way of doing things (though I have a really strong programming background) and I am finding this to be very... frustrating trying to get the Facebook Integration down. (That, and the sample unity project fails to compile in unity, but I recently learned why... and there isn't a Completed Project, like with the other SDKs... Again, very frustrating, as I'd like to be able to figure this out, and just get back to building my game.) As to Aaron's answer, I followed all of it except:

You can get the 'data' from an appid by calling FB.API:

call FB.AppRequest(...,data="life") => request id = 1234 later, a player visits your game with the request id 1234 you call FB.API("/1234") : the resulting JSON string will have a field data="life"

The main issue is that I am not fully getting how to get the specific AppRequests sent to a person, within the unity C-Sharp framework.

I would like, for example, to be able to send in my game a power-up called "Speed Up" to other players, and then pull the sent request (when the user logs in) and know how many/from who/etc they have received. I am using the below SendPowerUp function.

Here is the code used, it's mostly copied out of the FBUtil.cs file, and slightly modified to work with the 6.0beta sdk...

    public void SendPowerUp()
{
    DirectRequestTitle = "Send a Mystery Gift to a friend.";

    FriendFilters.Add ("all");
    FriendFilters.Add ("app_users");
    FriendFilters.Add ("app_non_users");

    // sends a gift request to players... 
    FB.AppRequest (
        message: DirectRequestMessage,
        actionType: OGActionType.Send, 
        objectId: "gift" + FB.UserId,
        filters: FriendFilters, 
        excludeIds: null, 
        maxRecipients: 49, 
        data: FriendSelectorData, 
        title: DirectRequestTitle, 
        callback: (Facebook.FacebookDelegate)AppRequestAsDirectRequestComplete);
}

This is a modified version of:

    public void CallAppRequestAsDirectRequest()
{
    if (DirectRequestTo == "")
    {
        throw new ArgumentException("\"To Comma Ids\" must be specificed", "to");
    }
    FB.AppRequest(
        message: DirectRequestMessage,
        to: DirectRequestTo.Split(','),
        title: DirectRequestTitle,
        callback: AppRequestAsDirectRequestComplete
    );
}

Because Unity gives this error when importing the script, if the parameters are missing:

Assets/Scripts/CSharp/FB_Controller.cs(287,12): error CS1501: No overload for method AppRequest' takes 4' arguments

Any explanation on how to get the requests that my app sends to a player when they play my game, (from FACEBOOK) would be greatly appreciated.

I had a question similar to this and ended up coming up with a hacky solution here: Facebook Unity and handling app requests

I'm sure there's a much simpler and more elegant solution out there somewhere, but it's working well enough for me. I forgot to mention in the answer that you can include a 'data' string when sending the AppRequest, which can then be read back from the JSON to handle the request type (life, for example).

All the information is on this page here: https://developers.facebook.com/docs/games/services/gamerequests

Although a lot of it isn't Unity-specific, which is why my answer was so hacky. The way I tested it was by sending requests between test users. You can check all requests in a browser by using this link: https://graph.facebook.com/me/apprequests?access_token=[USER ACCESS TOKEN]

And replacing USER ACCESS TOKEN with the test user access token. This also helps to determine whether or not the request has been deleted after you process it.

Also, for the AppRequest function, there are multiple ways in which it can take parameters in different orders. You can cycle through them by typing (in Monodevelop/Visual Studio) FB.AppRequest(

That should show the parameters, and they can be cycled through by hitting the arrow keys.

Hope this helps!

EDIT: Just realized this was asked 2 years ago. Hopefully you've already found a solution.

https://www.facebook.com/gaming/play/poppin-jump The reason for the initial start-up speed of this on facebook site is slower than other games. Why?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM