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));
}
}