简体   繁体   English

Facebook 图形 API/FB UNITY SDK 处理应用请求(发送和接收)

[英]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首先,这是与我的特定帮助请求相关的原始问题线程的链接: 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.这是我在这里的第一个问题,我现在已经尝试了 5 次,只是为了让它看到超过 5 分钟。

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.我的原始评论:@Aaron,感谢您对上述链接的回复,因为我发现它试图弄清楚如何做 Nick Mascarenhas 也在努力弄清楚的事情。 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.我(作为 Unity 开发人员)还希望看到一个 GetRequests 类型的函数,它返回一个来自用户 ID 的数组和发送给登录用户的请求代码。我对 Facebook 的做事方式很陌生(虽然我有一个非常强大的编程背景),我发现这非常......试图让 Facebook 集成失败。 (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: (那个,并且示例统一项目无法统一编译,但我最近了解到为什么......并且没有像其他 SDK 那样的已完成项目......再次,非常令人沮丧,因为我想能够弄清楚这一点,然后重新开始构建我的游戏。)至于 Aaron 的回答,我遵循了所有内容,除了:

You can get the 'data' from an appid by calling FB.API:您可以通过调用 FB.API 从 appid 获取“数据”:

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"调用 FB.AppRequest(...,data="life") => request id = 1234 之后,玩家使用你调用 FB.API("/1234") 的请求 ID 1234 访问你的游戏:生成的 JSON 字符串将有一个字段 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.主要问题是我没有完全了解如何在统一 C-Sharp 框架内将特定的 AppRequests 发送给一个人。

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.我正在使用下面的 SendPowerUp 函数。

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...这是使用的代码,它主要是从 FBUtil.cs 文件中复制出来的,并稍作修改以与 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:因为Unity在导入脚本的时候会报这个错误,如果缺少参数:

Assets/Scripts/CSharp/FB_Controller.cs(287,12): error CS1501: No overload for method AppRequest' takes 4' arguments Assets/Scripts/CSharp/FB_Controller.cs(287,12): 错误 CS1501: AppRequest' takes方法没有重载AppRequest' takes 4' 个参数

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.关于如何获取我的应用程序在玩我的游戏时发送给玩家的请求的任何解释(来自 FACEBOOK)将不胜感激。

I had a question similar to this and ended up coming up with a hacky solution here: Facebook Unity and handling app requests我有一个与此类似的问题,最终在这里提出了一个骇人听闻的解决方案: Facebook Unity and processing 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).我忘了在答案中提到您可以在发送 AppRequest 时包含一个“数据”字符串,然后可以从 JSON 读回以处理请求类型(例如生命)。

All the information is on this page here: https://developers.facebook.com/docs/games/services/gamerequests所有信息都在此页面上: 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.尽管其中很多不是特定于 Unity 的,但这就是为什么我的回答如此笨拙的原因。 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]您可以使用以下链接在浏览器中查看所有请求: https ://graph.facebook.com/me/apprequests ? access_token =[ USER ACCESS TOKEN]

And replacing USER ACCESS TOKEN with the test user access token.并用测试用户访问令牌替换 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.此外,对于 AppRequest 函数,它可以通过多种方式以不同的顺序获取参数。 You can cycle through them by typing (in Monodevelop/Visual Studio) FB.AppRequest(您可以通过键入(在 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.编辑:刚刚意识到这是 2 年前提出的问题。 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. https://www.facebook.com/gaming/play/poppin-jump在Facebook网站上进行此操作的初始启动速度比其他游戏要慢。 Why? 为什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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