CLIENT_ID: not found. using google api and laravel

  google-api, laravel, laravel-8

I’m trying to use laravel and google analytics to be able to build a report, the problem I’m getting is this

{ "error": { "code": 400, "message": "CLIENT_ID: {my_client_id} not found.", "errors": [ { "message": "CLIENT_ID: {my_client_id} not found.", "domain": "global", "reason": "badRequest" } ], "status": "INVALID_ARGUMENT" } }

Here is my code

    <?php

    namespace AppHttpControllers;

    use CarbonCarbon;
    use Google_Service_AnalyticsReporting_User;
    use IlluminateSupportFacadesHttp;

    // Google API
    use GoogleClient;
    use Google_Service_AnalyticsReporting_SearchUserActivityRequest;
    use Google_Service_AnalyticsReporting_ReportRequest;
    use Google_Service_AnalyticsReporting_Metric;
    use Google_Service_AnalyticsReporting_GetReportsRequest;
    use Google_Service_AnalyticsReporting_DateRange;
    use Google_Service_AnalyticsReporting;

    class GAActivityController extends Controller
    {
        public function index()
        {
            $startDate = Carbon::now()->firstOfMonth();

            $client = new Client();
            $client->setAuthConfig(storage_path('test-api.json'));
            $client->addScope(Google_Service_Analytics::ANALYTICS_READONLY);

            $analytics = new Google_Service_AnalyticsReporting($client);

            $user = new Google_Service_AnalyticsReporting_User();
            $user->setUserId(env('CLIENT_ID')); //Client ID

            $userActivityRequest = new Google_Service_AnalyticsReporting_SearchUserActivityRequest();
            $userActivityRequest->setViewId(env('ANALYTICS_VIEW_ID'));
            $userActivityRequest->setUser($user);

            $param = [

            ];

            dd($analytics->userActivity->search($userActivityRequest, $param));
        }
    }

Source: Laravel

Leave a Reply