2016-04-02 97 views
1

因此,我一直在努力將排行榜實施到我的移動應用程序幾乎整天,並且除了顯示朋友的個人資料圖片外,到他們的分數。如何在Unity C中顯示Facebook朋友個人資料圖片#

在V6.x中,你可以使用FB.GetPictureUrl但現在我認爲會有某種FB.API實現,它允許我做同樣的事情?

無論如何,這裏就是我正在做的事情

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(「/應用程序/分?場=得分, user.limit(30)「,HttpMethod.GET,ScoresCallBack);

所以,謝謝!有任何想法嗎?

回答

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。我還沒有測試這個代碼。

相關問題