0
     $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."

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449

1 Answers1

0

Users.dataSources: list requires one of the following scopes to use.

enter image description here

You appear to be using one of the ones on the list

Google_Service_Fitness::FITNESS_ACTIVITY_READ

And i have tested it that scope does allow a call to that api which means its not an issue with the API.

The problem is that you have probably authenticated the user then changed the scope in your code and not reauthenticated the user requesting the new scope. You need to login the user again

'approval_prompt' => 'force'

You need it to pop up and ask for the permission again

enter image description here

You may have to go to your google account and remove the apps permissions to reset it remove

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449