Skip to content

Instantly share code, notes, and snippets.

@gboudreau
Last active January 15, 2020 04:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gboudreau/8b8851a9c99140b6234856bbc80a2d24 to your computer and use it in GitHub Desktop.
Save gboudreau/8b8851a9c99140b6234856bbc80a2d24 to your computer and use it in GitHub Desktop.
Manually create cache file required for nest-api to work with Nest accounts (not Google accounts). Ref: https://github.com/gboudreau/nest-api/issues/110
<?php
echo "\nInstructions:\n";
echo " - Login to https://home.nest.com in your browser\n";
echo " - Once logged in, using the same tab, go to https://home.nest.com/session\n";
echo " - Copy-paste the text (JSON) here (then press ENTER):\n\n";
$json = readline();
$o = json_decode($json);
echo "\nThanks!\n\n";
$username = readline("What is your Nest username: ");
$password = readline("What is your Nest password: ");
$cache_file = sys_get_temp_dir() . '/nest_php_cache_' . md5($username . $password);
echo "\nWill create cache file at $cache_file ...\n";
$vars = array(
'transport_url' => $o->urls->transport_url,
'access_token' => $o->access_token,
'user' => $o->user,
'userid' => $o->userid,
'cache_expiration' => strtotime($o->expires_in)
);
file_put_contents($cache_file, serialize($vars));
echo "Done.\n";
echo "Access token will expire on $o->expires_in. You will need to re-execute this script before then.\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment