0

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 App\Http\Controllers;

    use Carbon\Carbon;
    use Google_Service_AnalyticsReporting_User;
    use Illuminate\Support\Facades\Http;

    // Google API
    use Google\Client;
    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));
        }
    }
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
Aurilie
  • 189
  • 3
  • 14
  • use config instead of `env('CLIENT_ID')` – Kamlesh Paul Oct 29 '20 at 06:56
  • @KamleshPaul - will do, but how would that solve my problem? Because even if I did that wouldn't I still get the same error? – Aurilie Oct 29 '20 at 06:58
  • `dd(env('CLIENT_ID') );` try this and check – Kamlesh Paul Oct 29 '20 at 07:01
  • you were just asking about activityTime what happened of that? – bhucho Oct 29 '20 at 07:01
  • If there is a setter, then there must be getter in this try to see if your user_id is set use, `$user->getUserId()` – bhucho Oct 29 '20 at 07:14
  • @KamleshPaul - I get my client_id. @bhucho - I deleted that question, because I thought it wasn't correct to have that one and this one, that it might be flagged as repeating my question, but if you think it's ok I can still undelete it. Also I've tried `dd($user->getUserId())` and I got my client ID back and when I didn't `dd()` I still got the same error as my question – Aurilie Oct 29 '20 at 07:32

0 Answers0