Hi! I'm new to using IoT Cloud and need help. I generated an API Key to connect my Arduino Uno R4 Wi-Fi to Unity. However, when I try to upload the script in Unity, the 404: Unauthorized error appears. Does anyone know how to solve the problem?
This is the script I use:
IEnumerator GetHeartRate()
{
string url = "https://api2.arduino.cc/iot/v2/things/{thingId}/properties/{propertyId}/"; // Replace with your API endpoint
UnityWebRequest request = UnityWebRequest.Get(url);
// Replace "YOUR_ACCESS_TOKEN" with the correct token
string accessToken = "YOUR_ACCESS_TOKEN";
Debug.Log("Access Token: " + accessToken); // Debug to ensure token is correctly set
request.SetRequestHeader("Authorization", "Bearer " + accessToken);
yield return request.SendWebRequest();
if (request.result != UnityWebRequest.Result.Success)
{
Debug.LogError("Error: " + request.error); // Log the error
Debug.LogError("Response Code: " + request.responseCode); // Log the HTTP response code
}
else
{
string jsonResult = request.downloadHandler.text;
Debug.Log("Heart rate data: " + jsonResult); // Process the data
}
}