簡體   English   中英

如何在Unity C中顯示Facebook好友資料圖片#

[英]How to display a Facebook friends profile picture in Unity C#

所以,我幾乎整天都在努力將排行榜應用到我的移動應用程序中,除了在他們的分數旁邊顯示朋友的個人資料圖片外,我已經成功地完成了所有工作。

在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(“/ app/scores?fields=score,user.limit(30)”,HttpMethod.GET,ScoresCallBack);

那謝謝啦! 有任何想法嗎?

您可以通過以下方式獲取個人資料照片

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

這就是我處理類似事情的方式。 將所有基本數據(user_name,score)加載到預制列表項后,每個列表項都負責加載自己的配置文件圖片。

在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());
        }
    });
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM