Facebook Unity并处理应用程序请求 [英] Facebook Unity and handling app requests

查看:153
本文介绍了Facebook Unity并处理应用程序请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我提出了我原来的问题,因为我设法通过跟踪和错误,大量深入的搜索来弄清楚。
所以,我明白,在Unity中使用最新的Facebook SDK,您可以使用以下方式提取播放器的所有待处理请求:

  FB.API(/ me / apprequests,HttpMethod.GET,RequestHandler)

WhereHandHandler是一个IGraphResult,然后您可以解析为Dictionary,如下所示:

  void RequestHandler(IGraphResult result){
if(result!= null){
Dictionary< string,object> reqResult = Json.Deserialize(result.RawResult)as Dictionary< string,object> ;;
}

}



该文档解释了如何以JSON格式显示单一请求,并且我已经找到了一些如何处理该信息的示例(我模糊地理解JSON),但是如果为播放器提取所有请求,我如何处理这个信息?



在JSON中,我只是试图拉取每个请求的对象ID和发件人ID,根据对象ID处理请求,然后删除从图中连接两个请求,我想我已经想到了。



所以我的问题是,对于每个请求,我如何提取对象和发件人ID?

解决方案

所以经过大量的试错和大量的日志检查,我已经弄清楚了真的很奇怪的做法,对于那些不确定的人:

  public void TestRequests(){
FB .API(/ me / apprequests,HttpMethod.GET,TestRespo NSE);
}

public void TestResponse(IGraphResult result){
if(result.Error == null){
//以字典的形式获取所有请求。
字典< string,object> reqResult = Json.Deserialize(result.RawResult)as Dictionary< string,object> ;;
//抓取数据,并将其放在对象列表中。
列表< object> newObj = reqResult [data] as List< object> ;;
//对于newObj中的每个项目都是单独的请求,因此每个单独的请求都是单独的。
for(int xx = 0; xx< newObj.Count; xx ++){
Dictionary< string,object> reqConvert = newObj [0] as Dictionary< string,object> ;;
字典< string,object> fromString = reqConvert [from]为Dictionary< string,object> ;;
字典< string,object> toString = reqConvert [to] as Dictionary< string,object> ;;
string fromName = fromString [name] as string;
string fromID = fromString [id] as string;
string obID = reqConvert [id] as string;
string message = reqConvert [message] as string;
string toName = toString [name] as string;
string toID = toString [id] as string;
Debug.Log(Object ID:+ obID);
Debug.Log(Sender message:+ message);
Debug.Log(Sender name:+ fromName);
Debug.Log(Sender ID:+ fromID);
Debug.Log(收件人名称:+ toName);
Debug.Log(收件人ID:+ toID);
}
}
else {
Debug.Log(Something wrong wrong。+ result.Error);
}
}

再次,这是我第一次使用JSON的经验,我确定有一个更有效的方法,但基本上经过大量的分解和转换,我已经设法提取对象ID,发件人名称和ID,附加的消息和收件人的名称和ID 。对象ID与接收者ID进行连接,因此要对对象ID本身进行操作,这将需要删除,但是它将使得更容易传递字符串以从Graph API中删除请求。 p>

如果有人可以向我建议一个更有效的方法,我将不胜感激!毕竟,总是有更多的学习。


I pulled my original question because I managed to figured it out through trail and error and a lot of deep searching. So, I understand that using the latest Facebook SDK in Unity, you can pull all pending requests for a player using:

FB.API("/me/apprequests", HttpMethod.GET, RequestHandler)

Where RequestHandler is an IGraphResult, which you can then parse into a Dictionary, like so:

void RequestHandler(IGraphResult result){
    if (result != null) {
        Dictionary<string, object> reqResult = Json.Deserialize(result.RawResult) as Dictionary<string, object>;
    }

}

The documentation explains how a singular request will be displayed in JSON format, and I've found a few examples of how to work with that information (I vaguely understand JSON's), however if pulling ALL requests for the player, how do I work with this information?

Out of the JSON, I'm just trying to pull the object ID and sender ID of each request, handle the request based on the object ID then delete the request from the graph by concatenating the two, which I think I've figured out already.

So my question is, for each request, how do I extract the object and sender ID's?

解决方案

So after a LOT of trial and error and a lot of Log checks, I've figured out a really hacky way of doing it, for those that aren't sure:

public void TestRequests(){
    FB.API("/me/apprequests", HttpMethod.GET, TestResponse);
}

public void TestResponse(IGraphResult result){
    if (result.Error == null) {
        //Grab all requests in the form of  a dictionary.
        Dictionary<string, object> reqResult = Json.Deserialize(result.RawResult) as Dictionary<string, object>;
        //Grab 'data' and put it in a list of objects.
        List<object> newObj = reqResult["data"] as List<object>;
        //For every item in newObj is a separate request, so iterate on each of them separately.
        for(int xx = 0; xx < newObj.Count; xx++){
            Dictionary<string, object> reqConvert = newObj[0] as Dictionary<string, object>;
            Dictionary<string, object> fromString = reqConvert["from"] as Dictionary<string, object>;
            Dictionary<string, object> toString = reqConvert["to"] as Dictionary<string, object>;
            string fromName = fromString["name"] as string;
            string fromID = fromString["id"] as string;
            string obID = reqConvert["id"] as string;
            string message = reqConvert["message"] as string;
            string toName = toString["name"] as string;
            string toID = toString["id"] as string;
            Debug.Log ("Object ID: " + obID);
            Debug.Log ("Sender message: " + message);
            Debug.Log ("Sender name: " + fromName);
            Debug.Log ("Sender ID: " + fromID);
            Debug.Log ("Recipient name: " + toName);
            Debug.Log ("Recipient ID: " + toID);
        }
    } 
    else {
        Debug.Log ("Something went wrong. " + result.Error);
    }
}

Again, this is my first experience with using JSON, and I'm sure there's a much more efficient way of doing this, but basically after a lot of breaking down and converting, I've managed to extract the object ID, sender name and ID, the message attached and the recipient name and ID. The object ID comes concatenated with the recipient ID, so to operate on the object ID itself, this will need to be removed, however as is it will make it easier to pass the string on to remove the request from the Graph API.

If anyone can suggest to me a more efficient way of doing this, I'd be grateful! There's always more to learn, after all.

这篇关于Facebook Unity并处理应用程序请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆