2

I'm trying to figure out how to connect my NestDK app to the nest API. After Login in with my user and password, I am getting a "Use this Pincode to connect with Nest. XXXXXX". What am I supposed to do with this ? I expected the access_token request to be happening in the background but I get stuck on this page.

I set REDIRECT_URL to https://api.home.nest.com/oauth2/access_token?client_id=[myClientId]&code=AUTHORIZATION_CODE&client_secret=[myClientSecret]&grant_type=authorization_code

Any idea ?

Thanks

Patrice
  • 1,404
  • 1
  • 14
  • 27

2 Answers2

5

I finaly found my mistake.

The REDIRECT_URL is to be set in the client registration page on the nest developer website and NOT ONLY in Constants.java.

I put http://localhost/ on both location and it worked immediatly.

Patrice
  • 1,404
  • 1
  • 14
  • 27
  • I have been looking over this documentation for a couple of hours and I must be missing something ....... I feel like you had the same problem but I don't see how localhost fixes it. So in the Products page there is a "Redirect URI" - What goes here???? It just says "any URL that you choose" - uhhhhh what? – boltup_im_coding Feb 23 '16 at 06:42
0

I played wrestling with this topic myself. After spending much time looking through the documentation I realized that the PIN is needed to get the Authorization Code. This is a separate request. You only need to issue it once for each pin. (Indeed, it seems that you can only make the call once so save the output from the call.)

You can do this either in a terminal using CURL (as it is in the documentation) or through a REST call to the authentication server. I have provided a javascript version of this that I have used successfully in a Google Script:

/**
 * This only works once for each PIN generation. Subsequent calls will fail.
 * @param {String} user_pin the pin generated from the website
 */
function getNESTAuthorization(user_pin) {
  var client_id = 'put your client id here';
  var client_secret = 'put your client secret here';
  // var user_pin = 'this is the pin you got from setting up the connection'

  var theURL =
    'https://api.home.nest.com/oauth2/access_token?code=' + user_pin +
    '&client_id=' + client_id +
    '&client_secret=' + client_secret +
    '&grant_type=authorization_code';

  var options = {
    "method": "post",
    "payload": ""
  };

  var resp = UrlFetchApp.fetch(theURL, options); // return is a JSON string
  eval('var answer = ' + resp.getContentText());

  Logger.log(answer.access_token); // This is the unbelievably long authentication token
         // you need this for subsequent calls. 

  return answer.access_token;

}

There is probably some cool way to do this using the OAuthConfig structure but I haven't worked that one out yet.

Paul B
  • 1
  • 1
  • the android-NestDK app should be doing this on it own, isn't it ? the question is how do I intercept the pin from within the app ? – Patrice Dec 15 '14 at 10:51