cancel
Showing results for 
Search instead for 
Did you mean: 
Replies are disabled for this topic. Start a new one or visit our Help Center.

How use API Nest Cam

ErenTURKOGLU
Community Member

Hi,

I have a Nest Cam Battery and I would use the API Nest for my site web. But I can't.

And also I learn that we will can't use Nest in a month. How I can do for use the API?

 

I use this code PHP :

$url = "https://developer-api.nest.com/devices/cameras/".$deviceid."/is_online";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
$data = curl_exec($curl);

if(curl_errno($curl)) {
    echo "Erreur cURL : " . curl_error($curl);
}

curl_close($curl);
echo("Online : ".$data);

When I run the code :

Online : {"error":"unauthorized","type":"https://developer.nest.com/documentation/cloud/error-messages#auth-error","message":"unauthorized","instance":"92045a0b-1683-4d6f-bcd3-0c298916f40f"}

How I can solve this error and what i will do after a month?

Sorry for my bad English.

3 REPLIES 3

David_K
Diamond Product Expert
Diamond Product Expert

This isn't a supported way of working with Nest products anymore, I'm afraid. See below:

Support for Works with Nest ending - Google Nest Help

For advanced needs, Google launched the Google Home script editor which launched recently in preview:

Create advanced home automations with the script editor - Google Nest Help

Hi,

Ok. Thanks. Now I try to use Device Access and API of SDM. But I get this error : 

Array ( [error] => Array ( [code] => 404 [message] => Requested entity was not found. [status] => NOT_FOUND ) )

I try to get RTSP Token and videourl.

Firstly I get the access token and after in try to get videourl and data rtsp.

I use this code PHP : 

 

function getRTSPToken($client_id, $client_secret, $project_id, $device_id, $refresh_token) {

 

    $auth_url = "https://www.googleapis.com/oauth2/v4/token";

    $auth_data = array(

        'client_id' => $client_id,

        'client_secret' => $client_secret,

        'refresh_token' => $refresh_token,

        'grant_type' => 'refresh_token'

    );

 

    // Effectuez une requête HTTP POST pour obtenir le nouveau jeton d'accès

    $auth_curl = curl_init($auth_url);

    curl_setopt($auth_curl, CURLOPT_POST, true);

    curl_setopt($auth_curl, CURLOPT_POSTFIELDS, http_build_query($auth_data));

    curl_setopt($auth_curl, CURLOPT_RETURNTRANSFER, true);

    $auth_response = curl_exec($auth_curl);

    curl_close($auth_curl);

 

    // Analysez la réponse JSON pour obtenir le nouveau jeton d'accès

    $auth_data = json_decode($auth_response, true);

    if (isset($auth_data['access_token'])) {

        $access_token = $auth_data['access_token'];

 

        $api_url = "https://smartdevicemanagement.googleapis.com/v1/enterprises/$project_id/devices/$device_id:executeCo...";

        $api_headers = array(

            'Authorization: Bearer ' . $access_token,

            'Content-Type: application/json',

        );

 

        $api_data = array(

 

            'command' => 'sdm.devices.commands.CameraLiveStream.GenerateRtspStream',

            'params' => array(

                'streamType' => 'LIVE_STREAM' // Vous pouvez ajuster les paramètres ici si nécessaire

            ),

        );

 

        // Convertir les données en JSON

        $api_data_json = json_encode($api_data);

        // Effectuez une requête HTTP POST pour obtenir le token RTSP

        $api_curl = curl_init($api_url);

        curl_setopt($api_curl, CURLOPT_POST, true);

        curl_setopt($api_curl, CURLOPT_HTTPHEADER, $api_headers);

        curl_setopt($api_curl, CURLOPT_POSTFIELDS, $api_data_json);

        curl_setopt($api_curl, CURLOPT_RETURNTRANSFER, true);

        // Exécutez la requête HTTP

        $api_response = curl_exec($api_curl);

        curl_close($api_curl);

        // Analysez la réponse JSON pour obtenir le token RTSP

        $api_data = json_decode($api_response, true);

        print_r($api_data);

 

        if (isset($api_data['results']['rtspStream'])) {

            return $api_data['results']['rtspStream'];

        } else {

            return null;

        }

    } else {

        return null;

    }

}

 

$rtsp_token = getRTSPToken($client_id, $client_secret, $project_id, $device_id, $refresh_token);

 

How I can revolve this.

Thanks.

David_K
Diamond Product Expert
Diamond Product Expert

To get the best support with that, I'd recommend posting on Stackoverflow using the nest-device-access tag as this is outside the scope of what we support in this community.