(使用Unity 5.2.2、Unity Facebook SDK 7.2.2)
我试图在登录后获取我的Facebook个人资料图片,将其设置为Sprite
并设置为Image
。方法FBLogin()在单击Button
时调用。。
public void FBLogin()
{
perms = new List<string>() { "public_profile", "email", "user_friends" };
FB.LogInWithReadPermissions(perms, AuthCallback);
}
private void AuthCallback(ILoginResult result)
{
if (FB.IsLoggedIn)
{
//Get Facebook Details
getUserInfoFromFacebook();
}
else
{
Debug.Log("User cancelled login");
}
}
private void getUserInfoFromFacebook()
{
FB.API("/v2.5/me?fields=id,name,picture", Facebook.Unity.HttpMethod.GET, DealWithProfilePicture);
}
private void DealWithProfilePicture(IGraphResult result)
{
if (result.Error != null)
{
Debug.Log("Problem with getting profile picture");
FB.API("/v2.5/me?fields=id,name,picture",Facebook.Unity.HttpMethod.GET, DealWithProfilePicture);
Debug.Log(result.Error);
return;
}
profile_picture.sprite = Sprite.Create(result.Texture, new Rect(0,0,128,128), new Vector2(0,0));
}
我根本无法掌握API语法的诀窍——它会产生错误400 Bad Request
。有人能帮我学语法吗?
感谢
您可以在该文档中看到,图片不是用户的字段,而是一个额外的边缘,可以通过请求/me/picture
:来检索
FB.API("/me/picture",HttpMethod.GET,delegate(IGraphResult result) {
if (string.IsNullOrEmpty(result.Error))
{
Debug.Log("received texture with resolution "+result.Texture.width + "x" + result.Texture.height);
profile_picture.sprite = Sprite.Create(result.Texture, new Rect(0,0,128,128), new Vector2(0,0));
}
else
{
Debug.LogWarning("received error="+result.Error);
}
});