Hi folks.
I’m using Services Web API for dedicated server and I want to connect to services (in this example I try to get data from cloud-save) with “STATELESS_ACCESS_TOKEN”, but I got this error:
HTTP/1.1 401 Unauthorized error:{"status":401,"title":"Unauthorized", "detail":"Invalid Authorization header","code":51,"type":"https://services.docs.unity.com/docs/errors#51"}
public static async Task<CloudSaveReceivedPlayerData> GetPlayerInfo()
{
string url = $"https://services.api.unity.com/cloud-save/v1/data/projects/{_projectId}/environments/{_environmentId}/players/{_playerId}/items?keys=playerInfo";
using UnityWebRequest request = new(url, UnityWebRequest.kHttpVerbGET);
try
{
string token = $"Bearer {_adminAccessToken}";
request.SetRequestHeader("Content-Type", "application/json");
request.SetRequestHeader("Authorization", token);
request.downloadHandler = new DownloadHandlerBuffer();
await request.SendWebRequest();
if (request.result != UnityWebRequest.Result.Success)
return null;
CloudSaveReceivedData receivedData = JsonUtility.FromJson<CloudSaveReceivedData>(request.downloadHandler.text);
if(receivedData == null)
return null;
CloudSaveReceivedPlayerData playerData = receivedData.results[0];
return playerData;
}
catch (Exception ex)
{
return null;
}
}
Actually, I can take the data with base64 (SERVICE_ACCOUNT_CREDENTIALS) string, but I want to know what is problem in this code?
This works correctly.
curl -H "Authorization: Basic < SERVICE_ACCOUNT_CREDENTIALS >" \
https://services.api.unity.com/<ENDPOINT>
Thanks.