我正在使用 Unity3D v5.3.1f1 和适用于Unity v7.2.0的Facebook SDK 为Android + iOS开发游戏。游戏中有排行榜,显示在Facebook上保存的分数,还有个人资料图片。
代码实现如下:
// Generate Graph API query for a user/friend's profile picture
public static string GetPictureQuery(string facebookID, int? width = null, int? height = null, string type = null, bool onlyURL = false)
{
string query = string.Format("/{0}/picture", facebookID);
string param = width != null ? "&width=" + width.ToString() : "";
param += height != null ? "&height=" + height.ToString() : "";
param += type != null ? "&type=" + type : "";
if (onlyURL) param += "&redirect=false";
if (param != "") query += ("?g" + param);
return query;
}
string ids = "friend id here";
void loadFBProfilePicture()
{
string query = GraphUtil.GetPictureQuery(ids, 100, 100, "normal");
FB.API(query, HttpMethod.GET, dealWithProfPic);
}
void dealWithProfPic(IGraphResult result)
{
Debug.Log("Callback called!");
if (result.Error != null)
{
return;
}
profpic.sprite = Sprite.Create(result.Texture, new Rect(0, 0, 100, 100), new Vector2(0, 0));
}
程序只需要调用loadFBProfilePicture
函数,然后回调函数dealWithProfPic
将纹理分配给精灵。这在Android和Android上完美运行Unity Editor,但不适用于iOS!
经过一些调试,我发现的问题是,从不调用回调。记录消息"回调叫"永远不会出现在调试窗口上。
已经尝试的解决方案是将Facebook SDK for Unity升级到v7.3.0,但仍然没有结果。
其他信息:在带有iOS 9.2的Ipad Air 2上进行测试
编辑(2016年1月25日): Facebook已经确认这是link
的错误