我提出了我最初的问题,因为我通过反复试验、错误和大量的深入搜索,设法弄清楚了这个问题。因此,据我所知,使用Unity中最新的Facebook SDK,您可以使用以下命令拉取所有针对某个玩家的未决请求:
FB.API("/me/apprequests", HttpMethod.GET, RequestHandler)
其中RequestHandler是一个IGraphResult,然后您可以将其解析为字典,如下所示:
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?
发布于 2016-02-12 17:00:23
因此,在经历了大量的试错和大量的日志检查之后,对于那些不确定的人,我已经找到了一种非常老套的方法:
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);
}
}
同样,这是我第一次使用JSON,我确信有一种更有效的方法来实现这一点,但基本上在经过大量分解和转换之后,我已经设法提取了对象ID、发送者姓名和ID、附加的消息以及接收者的姓名和ID。对象ID与接收者ID连接在一起,因此要对对象ID本身进行操作,需要将其删除,但是这样可以更容易地传递字符串,以便从Graph API中删除请求。
如果有人能向我建议一种更有效的方法,我将不胜感激!毕竟,总会有更多的东西需要学习。
https://stackoverflow.com/questions/35354601
复制相似问题