所以,我几乎整天都在努力将排行榜应用到我的移动应用程序中,除了在他们的分数旁边显示朋友的个人资料图片外,我已经成功地完成了所有工作。
在V6.x中你可以使用 FB.GetPictureUrl 但现在我希望有某种 FB.API 实现允许我做类似的事情吗? / p>
无论如何,这就是我做事的方式
private void ScoresCallBack(IGraphResult result)
{
int num = -1;
var dataList = result.ResultDictionary ["data"] as List<object>;
foreach (Transform child in leaderboardPanel.transform)
{
GameObject.Destroy (child.gameObject);
}
foreach (object player in dataList)
{
num++;
var dataDict = dataList [num] as Dictionary<string, object>;
long score = (long)dataDict ["score"];
var user = dataDict ["user"] as Dictionary<string, object>;
string userName = user ["name"] as string;
string userID = user ["id"] as string;
GameObject ScorePanel;
ScorePanel = Instantiate (scoreEntryPanel) as GameObject;
ScorePanel.transform.SetParent (leaderboardPanel.transform, false);
ScorePanel.SetActive (true);
ScorePanel.transform.GetChild(1).GetComponent<Text>().text = userName;
ScorePanel.transform.GetChild (2).GetComponent<Text> ().text = score.ToString ();
}
}
哦,我正在进行的API调用是
FB.API(“/ app/scores?fields=score,user.limit(30)”,HttpMethod.GET,ScoresCallBack);
所以,谢谢!有什么想法吗?
答案 0 :(得分:0)
您可以通过
获取个人资料照片FB.Api("{facebook_id}?fields=picture", HttpMethod.GET, PictureCallBack)
然后,您需要为下载纹理发出http请求并更新它。
希望这有帮助!!
private void PictureCallBack(IGraphResult result) {
JSONObject json = new JSONObject(result.RawResult);
StartCoroutine(DownloadTexture(json["picture"]["data"]["url"].str, profile_texture));
}
IEnumerator DownloadTexture(string image_url, Image profile_picture) {
WWW www = new WWW(url);
yield return www;
profile_picture = = www.texture;
}
PS。我还没有测试这段代码。
答案 1 :(得分:0)
这就是我处理类似问题的方式。将所有基本数据(用户名,分数)加载到预制列表项后,每个列表项负责加载自己的个人资料图片。
在FacebookScript中
public void downloadProfilePic(string user_id, FacebookDelegate<IGraphResult> callback){
FB.API("https" + "://graph.facebook.com/" + user_id + "/picture?
type=square&height=128&width=128", HttpMethod.GET, callback);
}
然后从ListViewItem脚本
private void downloadProfilePic(string user_id){
FindObjectOfType<FacebookScript>().downloadProfilePic(user_id, delegate (IGraphResult result){
if(result.Texture){
profileImage.sprite = Sprite.Create(result.Texture, new Rect(0, 0, 128 , 128), new Vector2());
}
});
}