Question by
ajaxis · Dec 23, 2020 at 04:16 PM ·
unity analytics
How can i use unity analytics Raw Data Export using Rest API
I want to export my analytics data using unity analytics raw data export, but i am getting error 400 everytime, tried multiple solutions on forums but did'nt find any luck. I am trying to achieve this using this code.
IEnumerator PostRequest() {
string jsonText = JsonUtility.ToJson(json);
Debug.Log(json);
//Auth token for http request
string accessToken;
Debug.Log(URL);
using (UnityWebRequest www = UnityWebRequest.Post(URL, jsonText))
{
www.SetRequestHeader("accept", "application/json");
www.SetRequestHeader("Content-Type", "application/json");
//accessToken = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(ProjectID+":"+APIKey));
www.SetRequestHeader("Authorization", "Basic " + GetAuthToken());
//Add the custom headers
www.uploadHandler = new UploadHandlerRaw(System.Text.Encoding.UTF8.GetBytes(jsonText));
Debug.Log(www.uploadHandler);
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Debug.LogError("ERROR title: " + www.error);
Debug.LogError("ERROR body: " + www.downloadHandler.text);
}
else
{
Debug.Log("Success");
Debug.Log("Success body: " + www.downloadHandler.text);
}
}
}
private string GetAuthToken()
{
string username = ProjectID;
string password = APIKey;
string authKV = username + ":" + password;
byte[] convertedToBytes = Encoding.UTF8.GetBytes(authKV);
string convertedToBase64 = Convert.ToBase64String(convertedToBytes);
//Debug.Log(convertedToBase64);
return convertedToBase64;
}
Comment
Your answer
Follow this Question
Related Questions
Aggregating Analytics Data 0 Answers
Unity Analytics not updating data since last 3 days 0 Answers
Unity Analytics Custom Event JS 0 Answers
Unity Analytics: Custom A/B 0 Answers
How to turn of certain aspects of unity analytics? 0 Answers