Unity Facebook AppRequestCallback
本文关键字:AppRequestCallback Facebook Unity | 更新日期: 2023-09-27 17:50:14
当我发送应用程序请求后,我有一个问题,以获得用户的id。在facebook手册中,它被描述为
"已创建请求的接收方用户id数组。"
https://developers.facebook.com/docs/unity/reference/current/FB.Apprequest
我的回调代码是这样的:
if(responseObject.TryGetValue ("to", out to))
{
string[] output = (string[])to;
print(output.Length);
}
> 是这给了我错误提示:
"InvalidCastException:不能从源类型强制转换到目标类型。"
我也尝试过对象中的foreach字符串,但它只是转换。
我能得到一些帮助上得到的用户数量,我已经发送请求,请。
非常感谢。
首先将其强制转换为对象列表
if(responseObject.TryGetValue ("to", out to)) {
List<object> output = (List<object>)to;
print(output.Count);
foreach(object uid in output) {
print(uid.ToString());
}
}
private void RequestFriendsCallback(IGraphResult result)
{
if (!string.IsNullOrEmpty(result.RawResult))
{
var resultDictionary = result.ResultDictionary;
if (resultDictionary.ContainsKey("data"))
{
var dataArray = (List<object>)resultDictionary["data"];//2.1.4
var dic = dataArray.Select(x => x as Dictionary<string, object>).ToArray();
foreach (var item in dic)
{
string id = (string)item["id"];
var url = item.Where(x => x.Key == "picture").SelectMany(x => x.Value as Dictionary<string, object>).Where(x => x.Key == "data").SelectMany(x => x.Value as Dictionary<string, object>).Where(i => i.Key == "url").First().Value;
FriendData friend = Friends.Where(x => x.FacebookID == id).FirstOrDefault();
if (friend != null)
GetPictureByURL("" + url, friend);
}
}
if (!string.IsNullOrEmpty(result.Error))
{
Debug.Log(result.Error);
}
}
}