I have a schedule that goes every night and get Admob data for that day from the official api, and store every record with a status (true or false). and it works fine.
sometimes the google token might be expired, so I'll store a record with a status false, so when the Admin login and try to see his Admob revenue I can tell him that the token is expired and you have to renew the token, he login to google -> generate a new token,When i get a new token i got redirected to the following function :
$client = new Google_Client();
$client->addScope('https://www.googleapis.com/auth/admob.readonly');
$client->addScope('https://www.googleapis.com/auth/admob.report');
$client->setApplicationName('MyAPPName');
$client->setAccessType('offline');
$googleAccountKeyFilePath = storage_path('client_secret.json');
$client->setAuthConfig($googleAccountKeyFilePath);
$client->fetchAccessTokenWithAuthCode($request->code);
$user = auth()->user();
$user->google_token = $request->code;
$user->save();
$service = new \Google_Service_AdMob($client);
$accountName = $user->google_account_name;
$result = $service->accounts->get($accountName);
if($result){
//do the job and redirect with success message as we updated the token in our database
dispatch(new UpdatedFAiledDailyRevenueBasedOnTheNewToken($user, $service ));
request()->session()->flash('success', 'Processing this might take up to a few minutes please wait!');
return redirect('dashboard/reports/revenue');
}
this function works fine, it create a service and authenticate and all fine. when i get to the queue, I can't use the service that i passed in as a parameter and i get the following error :
Serialization of 'Closure' is not allowed
I also tried to create a new google Client - and Admob service inside the queue and it didn't work even though i can do it from the schedule it doesn't work if i try to create it in the queue:
{
//what i want to do is to get the admob failed data and retry with them
$failed_data = AdMobRevenue::where('status', false)->get();
//then lets create a service
$client = new Google_Client();
$client->addScope('https://www.googleapis.com/auth/admob.readonly');
$client->addScope('https://www.googleapis.com/auth/admob.report');
$client->setApplicationName('MyAppName');
$client->setAccessType('offline');
$googleAccountKeyFilePath = storage_path('client_secret.json');
$client->setAuthConfig($googleAccountKeyFilePath);
$client->fetchAccessTokenWithAuthCode($this->user->google_token);
$service = new \Google_Service_AdMob($client);
$result = $service->accounts->get($accountName);
/*=================Creating a new service didn't work================== */
}
the code above will throw the following error :
Google\Service\Exception: {
"error": {
"code": 401,
"message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential.....
}
Sorry for the long description, i just wanted to make everything clear, and will appreciate any help