Reputation: 179
I have product secret, product id and Authorization URL from Nest Account with Thermostat as added device. Using Authorization URL I have generated 8 characters Pin code and then using Access Token URL with POST Method I am getting response as below
{"access_token":"c.KDYfQh2vrkS0w4k4BtGcJPysmzAzb3uXNz2myCMcEko5dUnrs5022kPd6cJnn5sg97hzXbm9YDzkDELXiLW58Frj6b2GyawbWLQMmm2x0eqmqa0j9VMpVQz2UXZ0mC2nDp7EmgVqsqgAXXA6","expires_in":315360000}
in Postman. what should be my next step to read Nest Thermostat information ? Please help me
Upvotes: 0
Views: 462
Reputation: 51
For starters, never post any token you receive on the web, it could be used maliciously. That token only lasts for three days so you are good by now, but for next time.
The easiest way to go forward is to follow the example in the nest labs github account: https://github.com/nestlabs/android-sdk
But we can go a bit into detail. Im not sure if your trying to receive the information via post man or in actual code, but here are both explanations:
Content-Type ---> application/json
Authorization ---> Bearer c.KDYfQh2v.............
(Don't forget to add the word "Bearer "with space before the actual full access token.)
the token could be a NestToken object or just a String:
String token = "c.KDYfQh2vrkS0w4k4BtGcJPysmzAzb3uXNz2myCMcEko5....."
THEN call this function to connect:
nest.authWithToken(token, new NestListener.AuthListener() {
@Override
public void onAuthSuccess() {
// Handle success here. Start pulling from Nest API.
}
@Override
public void onAuthFailure(NestException e) {
// Handle exceptions here.
}
@Override
public void onAuthRevoked() {
// Your previously authenticated connection has become unauthenticated.
// Recommendation: Relaunch an auth flow with nest.launchAuthFlow().
}
});
FINALLY, choose what you want to listen to and call the correct funtion:
All thermostats:
nest.addThermostatListener(new ThermostatListener() {
@Override
public void onUpdate(@NonNull ArrayList<Thermostat> thermostats) {
// Handle thermostat update...
}
}
);
All smoke alarms:
nest.addSmokeCOAlarmListener(new SmokeCOAlarmListener() {
@Override
public void onUpdate(@NonNull ArrayList<SmokeCOAlarm> alarms) {
// Handle smoke+co alarm update...
} });
All cameras:
nest.addCameraListener(new CameraListener() {
@Override
public void onUpdate(@NonNull ArrayList<Camera> cameras) {
// Handle camera update...
}
});
OR Listen to changes to all structures:
nest.addStructureListener(new StructureListener() {
@Override
public void onUpdate(@NonNull ArrayList<Structure> structures) {
// Handle structure update...
}
});
Good luck.
Upvotes: 0
Reputation: 21
To get the Nest Thermostat information one time, you need to make a GET request with the following headers and url:
curl -v -L \
-H "Content-Type: application/json" \
-H "Authorization: Bearer c.YOUR_TOKEN_HERE" \
-X GET "https://developer-api.nest.com/"
Upvotes: 0