Languages

Menu
Sites
Language
Tizen wear: 401 response error when fetching data from Nest API

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.

Responses

6 Replies
Marco Buettner

Did u take a look at your request header? U can use fiddler for that.

Did u check if token has a real value? Which is non-null?

Maciej Malak

Yep,

Headers are fine. Yep, token is fine, as I wrote in my first post. 
And as I wrote - I've checked the REST query with different software/platforms even. 

Marco Buettner

I ask if u check the code with fiddler and co from the tizen device and not from other/different platforms etc.

I ask if u check the request header of the gear2 device.

I ask if u check the token in your code in the gear2 device.

John Ixion

Artik Cloud is a good starting point imo

https://developer.artik.cloud/

John Ixion

even SmartThings doesn't work with Nest btw

http://developer.smartthings.com/

Iqbal Hossain

Hi~

The main reason of 401:

401 "Unauthenticated": you can't do this because you haven't authenticated

Please check the credential one more time.

And please check again the policy in config.xml

You should allow the domain name in the policy and make true for the subdomain.

For example,

<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns:tizen="http://tizen.org/ns/widgets" xmlns="http://www.w3.org/ns/widgets" id="http://yourdomain/XYZ" version="1.0.0" viewmodes="maximized">
    <access origin="http://googleapis.com" subdomains="true"></access>
    <access origin="http://google.com" subdomains="true"></access>
    <access origin="*" subdomains="true"></access>
    <tizen:application id="mK4rPENnX6.GoogleMap" package="mK4rPENnX6" required_version="2.4"/>
    <content src="index.html"/>
    <feature name="http://tizen.org/feature/screen.size.all"/>
    <icon src="icon.png"/>
    <name>XYZ</name>
    <tizen:privilege name="http://tizen.org/privilege/location"/>
    <tizen:privilege name="http://tizen.org/privilege/internet"/>
    <tizen:privilege name="http://tizen.org/privilege/application.launch"/>
    <tizen:profile name="mobile"/>
</widget>

 

-Thanks