private IEnumerator FetchAllOutfits(string token, System.Action onComplete)
{
if (string.IsNullOrEmpty(token) || string.IsNullOrEmpty(applicationId))
{
Debug.LogError(“Invalid parameters for fetching outfits. Please check token and applicationId.”);
onComplete?.Invoke(null);
yield break;
}
string outfitsEndpoint = $"https://api.readyplayer.me/v1/assets?filter=usable-by-user-and-app&filterApplicationId={applicationId}&filterUserId={userID}";
using (UnityWebRequest request = UnityWebRequest.Get(outfitsEndpoint))
{
request.SetRequestHeader("Authorization", $"Bearer {token}");
request.SetRequestHeader("X-APP-ID", applicationId);
Debug.Log($"Request URL: {request.url}");
Debug.Log($"Authorization Header: Bearer {token.Substring(0, 10)}..."); // Only log first 10 characters of token
yield return request.SendWebRequest();
Debug.Log($"Response Code: {request.responseCode}");
if (request.result != UnityWebRequest.Result.Success)
{
Debug.LogError($"Failed to fetch outfits: {request.error}");
Debug.LogError($"Response Code: {request.responseCode}");
Debug.LogError($"Full Response: {request.downloadHandler.text}");
onComplete?.Invoke(null);
}
else
{
string responseJson = request.downloadHandler.text;
Debug.Log($"FetchAllOutfits response: {responseJson}");
try
{
JObject response = JObject.Parse(responseJson);
JArray assetsArray = (JArray)response["data"];
if (assetsArray != null && assetsArray.Count > 0)
{
JArray outfitsArray = new JArray(assetsArray.Where(a => (string)a["type"] == "outfit"));
onComplete?.Invoke(outfitsArray);
}
else
{
Debug.LogWarning("No assets found in the response.");
onComplete?.Invoke(new JArray());
}
}
catch (JsonException e)
{
Debug.LogError($"Error parsing JSON response: {e.Message}");
onComplete?.Invoke(null);
}
}
}
}
Is there a glaring error?