Skip to content Skip to sidebar Skip to footer

Facebook Unity And Handling App Requests

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,

Solution 1:

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:

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

publicvoidTestResponse(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"] asstring;
            string fromID = fromString["id"] asstring;
            string obID = reqConvert["id"] asstring;
            string message = reqConvert["message"] asstring;
            string toName = toString["name"] asstring;
            string toID = toString["id"] asstring;
            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.

Post a Comment for "Facebook Unity And Handling App Requests"