Hi folks :)
I'm currently developing quite simple app using NEST API:
- Tizen 2.3.1 SDK,
- web based (JS, HTML, CSS) application,
- wearable devices are the target,
- standalone app
- powered by Samsung Galaxy Gear S2 watch
The problem: I'm getting 401 error when I'm trying to get data from NEST API.
First I'm getting token and it works perfectly fine:
function authNest() {
$.ajax({
url: authUrl,
type: "POST",
dataType: "json",
success: function(data) {
console.log(data.access_token);
getNest(data.access_token);
},
error: function(err) {
console.log(err);
}
});
That means I'm properly paired with mobile phone, internet connection works and I have proper privileges. Token works for sure. I've checked it with Postman, curl command and with REST client app for Android (3 different solutions works fine).
After getting a token I'm making REST API call with that token, and it looks like that:
function get(token) {
$.ajax({
url: "nestdeveloperlink",
beforeSend: function(xhr) {
xhr.setRequestHeader("content-type", "application/json");
xhr.setRequestHeader("authorization", "Bearer " + token);
},
method: 'GET',
success: function (data) {
alert(JSON.stringify(data));
},
error: function(err){
console.log(JSON.stringify(err));
}
});
But then I'm getting an error response. I also tried request using only XMLHttpRequest (without ajax/jquery) - I'm getting the same error response.
Error:
{ "readyState":4,
"responseText":"{\"error\":\"unauthorized\",\"type\":\,\"message\":\"unauthorized\",\"instance\":\"bfd045c0-e7ff-4a75-bbba-e6199be03c4a\"}", "status":401, "statusText":"Unauthorized" }
So I'm getting server response at least. But I'm not authorize and I'm completely don't have idea WTF.
Are there some problems with oAuth2.0 on Tizen wear? Why the server don't want to accept my requests even though it returned token before? Maybe some hidden constrains?
Of course I've defined features and privileges in config.xml: internet, network.internet, network.wifi, download, location and so on.
Pls help :)
PS. Please note that external links are with spaces because of Tizen forum policy.