-
Notifications
You must be signed in to change notification settings - Fork 0
/
EventBriteOauthTest.cs
154 lines (98 loc) · 3.74 KB
/
EventBriteOauthTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using System;
public class EventBriteOauthTest : MonoBehaviour
{
private const string _API_KEY = "Nunya";
private const string _CLIENT_SECRET = "Nunya2";
private const string _PRIVATE_TOKEN = "Nunya3";
private const string _PUBLIC_TOKEN = "Nunya4";
private const string _REDIRECT__URI = "Nunya5";
//*** Event ID code for Beat the Box
private const string EVENT_ID = "62258182800723";
private const string ATTENDEE_TEST_ID = "6466110299";
private const string _BASE_REQUEST_URL = "https://www.eventbriteapi.com/v3/";
private const string _AUTHENTICATION_URL = "/users/me/?token=MYTOKEN";
private const string _REDIRECT_URI = "https://www.eventbrite.com/oauth/authorize?response_type=code&client_id=YOUR_API_KEY&redirect_uri=YOUR_REDIRECT_URI";
private const string ATTENDEE_REQUEST_URL = "events/{event_id}/attendees/{attendee_id}";
private string formattedString = "";
string id = "";
DateTime from = new DateTime();
DateTime to = new DateTime();
public void InitGetMeasurements()
{
StartCoroutine(GetMeasurements(id, from, to, (measurementResult) =>
{
string measurement = measurementResult;
//Do something with measurement
UnityEngine.Debug.Log(measurement);
}));
}
private IEnumerator GetAccessToken(Action<string> result)
{
Dictionary<string, string> content = new Dictionary<string, string>();
//Fill key and value
content.Add("grant_type", "client_credentials");
content.Add("client_id", "login-secret");
content.Add("client_secret", "secretpassword");
UnityWebRequest www = UnityWebRequest.Post("https://someurl.com//oauth/token", content);
//Send request
yield return www.Send();
if (!www.isNetworkError)
{
string resultContent = www.downloadHandler.text;
TokenClassName json = JsonUtility.FromJson<TokenClassName>(resultContent);
//Return result
result(json.access_token);
}
else
{
//Return null
result("");
}
}
private IEnumerator GetMeasurements(string id, DateTime from, DateTime to, Action<string> result)
{
Dictionary<string, string> content = new Dictionary<string, string>();
//Fill key and value
content.Add("MeasurePoints", id);
content.Add("Sampling", "Auto");
content.Add("From", from.ToString("yyyy-MM-ddTHH:mm:ssZ"));
content.Add("To", to.ToString("yyyy-MM-ddTHH:mm:ssZ"));
content.Add("client_secret", "secretpassword");
UnityWebRequest www = UnityWebRequest.Post("https://someurl.com/api/v2/Measurements", content);
string token = null;
yield return GetAccessToken((tokenResult) => { token = tokenResult; });
www.SetRequestHeader("Authorization", "Bearer " + token);
www.Send();
if (!www.isNetworkError)
{
string resultContent = www.downloadHandler.text;
MeasurementClassName rootArray = JsonUtility.FromJson<MeasurementClassName>(resultContent);
string measurements = "";
/* foreach (MeasurementClassName item in rootArray)
{
measurements = item.Measurements;
}*/
//Return result
result(measurements);
}
else
{
//Return null
result("");
}
}
}
[Serializable]
public class MeasurementClassName
{
public string Measurements;
}
[Serializable]
public class TokenClassName
{
public string access_token;
}