只需使用此代碼檢索當前的頭像:
FB.API("/me/picture?redirect=false", HttpMethod.GET, ProfilePhotoCallback);
private void ProfilePhotoCallback (IGraphResult result)
{
if (string.IsNullOrEmpty(result.Error) && !result.Cancelled) {
IDictionary data = result.ResultDictionary["data"] as IDictionary;
string photoURL = data["url"] as string;
StartCoroutine(fetchProfilePic(photoURL));
}
}
private IEnumerator fetchProfilePic (string url) {
WWW www = new WWW(url);
yield return www;
this.profilePic = www.texture;
//Construct a new Sprite
Sprite sprites = new Sprite();
//Create a new sprite using the Texture2D from the url.
//Note that the 400 parameter is the width and height.
//Adjust accordingly
sprite = Sprite.Create(www.texture, new Rect(0, 0, 50 ,50), Vector2.zero);
sprites = Sprite.Create(www.texture, new Rect(0, 0, 50 ,50), Vector2.zero);
}
和Retriving其他玩家的個人資料圖片,你必須先知道用戶ID。
這裏是檢查用戶ID代碼:
Facebook.Unity.AccessToken.CurrentAccessToken.UserId
使用後:
FB.API ("/" + userid + "/picture?redirect=false", HttpMethod.GET, ProfilePhotoCallback);
以檢索選定的用戶ID資料圖片。
我假設你在說這裏的用戶的個人資料圖像? https://developers.facebook.com/docs/graph-api/reference/user/picture // Facebook的CDN網址被認爲是短暫的,他們可以隨着時間的推移而改變,一旦工作的網址可能失效。因此,使用自動重定向響應的API調用是最容易做的事情。如果您想將圖像存儲在您的最終目錄中,那麼如果用戶選擇新的個人資料圖片或刪除現有圖片,則您有責任保持它們的最新狀態。 – CBroe
好的。我看到你明白我的問題。那麼如何獲得圖像文件?我需要將它保存到雲端。它用於在排行榜上顯示個人資料圖片。 –
爲什麼你需要將它保存到雲端?你在哪裏以及如何顯示它?爲什麼會自動重定向到CDN位置的API URL不夠? – CBroe