retrieving homesdata failing
After managing getting a valid token which is saved in a file
{
"access_token": "582a01ce6d1dbdd93a8b4759|5d46c5d07be7515c79b878fc10xxxxxx",
"refresh_token": "582a01ce6d1dbdd93a8b4759|87aa855c325bce57afbe85d602xxxxxx",
"expires_in": 10800,
"expire_in": 10800,
"scope": [
"read_station",
"read_bubendorff",
"write_bubendorff"
],
"timestamp_utc": "2025-05-07T08:19:56.1789699Z"
}
I try to request the homes data with this codesnippet after getting the token
private async Task MakeApiRequest()
{
try
{
var tokenJson = File.ReadAllText(TokenFilePath);
var token = JsonConvert.DeserializeObject<TokenResponse>(tokenJson);
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", token.AccessToken);
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
var response = await client.GetAsync(ApiUrl);
var content = await response.Content.ReadAsStringAsync();
await Task.Run(() => File.WriteAllText(OutputFilePath, content));
}
}
catch (Exception ex)
{
File.AppendAllText(@"C:\Path\To\error.log", DateTime.Now + " ERROR: " + ex.Message + Environment.NewLine);
}
}
unfortunately I am allways running into an errormessage below
{
"error": {
"code": 2,
"message": "Invalid access token"
}
}
what I tried so far is using the token which is created by trying out the request on the netatmo page
https://dev.netatmo.com/apidocumentation/control#homesdata
If I replace the token generated in the curl request shown on the netatmo page with the one I received from my request the above code snipped is bringing back a valid answer.
So why is the created token not working? any reason?
Comentarios
3 comentarios
I'm also encountering the same issue on Weather Station.
Access token my app got through API is invalid.
But token obtaining from https://dev.netatmo.com/apidocumentation/weather#getmeasure is working.
I ping NetatomoSupport through twitter.
https://x.com/sanadas/status/1920399914065952946
I received the information that my requests has reached the limits which are described here
I have checked my code and will integrate an counter as I cant see that it should have reached at all the limits. I am still in contact with the Support, but I learned that they have some public holidays and they will be back next week on monday or tuesday, so I have to wait
My issue was also resolved.
The root cause might be the same—I was refreshing the token too frequently (Document mentions refresh token limits are 24 in 24hours)
Thanks for sharing the information!
Iniciar sesión para dejar un comentario.