如何在Unity中使用FB.GetAppLink从App Request深层链接获取朋友Faceook ID?

时间:2016-08-28 00:18:59

标签: facebook facebook-graph-api unity3d

我正在使用Unity 5.4和最新的Facebook API(7.8)。

我试图在点击他们发给我的游戏请求后找出我的朋友Facebook ID。我已经调查过并且一直在使用FB.GetAppLink,但它似乎没有给我朋友的Facebook ID,只有我的Facebook ID和游戏ID。

我需要这些信息,以便在接受他们的挑战后,如果我成功,我可以寄回礼物。

由于

1 个答案:

答案 0 :(得分:0)

在经历了很多箍之后找到答案......

public void GetDeepLink ()
{
    FB.GetAppLink(DeepLinkCallBack);
}

public void DeepLinkCallBack(IAppLinkResult result)
{
    if (string.IsNullOrEmpty(result.Error))
    {
        IDictionary<string, object> dict = result.ResultDictionary;

        if (dict.ContainsKey("target_url"))
        {
            string url = dict["target_url"].ToString();
            string keyword = "request_ids=";
            int k = 0;
            while (k < url.Length - keyword.Length && !url.Substring(k, keyword.Length).Equals(keyword))
                k++;
            k += keyword.Length;
            int l = k;
            while (url[l] != '&' && url[l] != '%')
                l++;
            string id = url.Substring(k, l - k);

            FB.API("/" + id + "_" + AccessToken.CurrentAccessToken.UserId, HttpMethod.GET, DeepLinkCallBackCallBack);
        }
        else
        {
            Debug.Log("Applink Error :" + result.Error);
        }
    }
}

void DeepLinkCallBackCallBack(IGraphResult result)
{
    Debug.Log("Request callback");
    Debug.Log("========================");

    if (string.IsNullOrEmpty(result.Error))
    {
        IDictionary<string, object> dict = result.ResultDictionary;

        if (dict.ContainsKey("from"))
        {
            IDictionary<string,object> from = dict["from"] as Dictionary<string, object>;
            if (from.ContainsKey("name"))
            {
                Debug.Log(from["name"]);
                deepLinkUserName = from["name"].ToString();
            }
            if (from.ContainsKey("id"))
            {
                deepLinkUserName = from["name"].ToString();
                FB.API("/" + dict["id"], HttpMethod.DELETE, null);
            }
        }
    }
    else
    {
        Debug.Log("Error in request:" + result.Error);
    }
}