Google Fitness API in php

     $user = Socialite::driver('google')->user();

        // Set token for the Google API PHP Client
        $google_client_token = [
            'access_token' => $user->token,
            'refresh_token' => $user->refreshToken,
            'expires_in' => $user->expiresIn
        ];

        $client = new Google_Client();
        $client->setApplicationName("Laravel");
        $client->setDeveloperKey(env('GOOGLE_SERVER_KEY'));
        $client->setAccessToken(json_encode($google_client_token));
        $client->setScopes(Google_Service_Fitness::FITNESS_ACTIVITY_READ);

        $fitness_service = new Google_Service_Fitness($client);

        $dataSources = $fitness_service->users_dataSources;
        $dataSets = $fitness_service->users_dataSources_datasets;

        $listDataSources = $dataSources->listUsersDataSources("me");


        dd($dataSets);

I tried this but it always ended giving me
“domain”: “global”,
“reason”: “insufficientPermissions”,
“message”: “Insufficient Permission: Request had insufficient authentication scopes.”

Source: Laravel StackOverflow

Leave a Reply