Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

redataha's avatar

The payload is invalid. Problem with decastro4 package Gmail API

Having a problem to integrate decastro4 Laravel Gmail API, after creating the JSON encrypt file.

This is what I did.

Routes:

Route::get('/oauth/gmail', function (){
    return LaravelGmail::redirect();
});

Route::get('/oauth/gmail/callback', function (){
    LaravelGmail::makeToken();
    return redirect()->to('/');
});

Route::get('/oauth/gmail/logout', function (){
    LaravelGmail::logout(); //It returns exception if fails
    return redirect()->to('/');
});

this is the file:

-> storage -------------->app -------------------->gmail ----------------------------->tokens ---------------------------------------->gmail-json.json

This is the Gmail config file:

<?php

return [

	/*
	|--------------------------------------------------------------------------
	| Gmail Configuration
	|--------------------------------------------------------------------------
	|
	|
	|
	|  Scopes Available:
	|
	|   * all - Read, send, delete, and manage your email
	|   * compose - Manage drafts and send emails
	|   * insert - Insert mail into your mailbox
	|   * labels - Manage mailbox labels
	|   * metadata - View your email message metadata such as labels and headers, but not the email body
	|   * modify - View and modify but not delete your email
	|   * readonly - View your email messages and settings
	|   * send - Send email on your behalf
	|   * settings_basic - Manage your basic mail settings
	|   * settings_sharing - Manage your sensitive mail settings, including who can manage your mail
	|
	|   Leaving the scopes empty fill use readonly
	|
	|  Credentials File Name
	|
	*/

	'project_id' => env('GOOGLE_PROJECT_ID'),
	'client_id' => env('GOOGLE_CLIENT_ID''),
	'client_secret' => env('GOOGLE_CLIENT_SECRET'),
	'redirect_url' => env('GOOGLE_REDIRECT_URI', 'http://localhost:8000/test'),

	'state' => null,

	'scopes' => [
		'readonly',
		'modify',
	],

	/*
	|--------------------------------------------------------------------------
	| Additional Scopes [URL Style]
	|--------------------------------------------------------------------------
	|
	|   'additional_scopes' => [
	|        'https://www.googleapis.com/auth/drive',
	|        'https://www.googleapis.com/auth/documents'
	|   ],
	|
	|
	*/

	'additional_scopes' => [

	],

	'access_type' => 'offline',

	'approval_prompt' => 'force',

	/*
	|--------------------------------------------------------------------------
	| Credentials File Name
	|--------------------------------------------------------------------------
	|
	|   :email to use, clients email on the file
	|
	|
	*/

	'credentials_file_name' => env('GOOGLE_CREDENTIALS_NAME', 'gmail-json'),

	/*
	|--------------------------------------------------------------------------
	| Allow Multiple Credentials
	|--------------------------------------------------------------------------
	|
	|   Allow the application to store multiple credential json files.
	|
	|
	*/

	'allow_multiple_credentials' => env('GOOGLE_ALLOW_MULTIPLE_CREDENTIALS', true),

	/*
	|--------------------------------------------------------------------------
	| Allow Encryption for json Files
	|--------------------------------------------------------------------------
	|
	|   Use Laravel Encrypt in json Files
	|
	|
	*/

	'allow_json_encrypt' => env('GOOGLE_ALLOW_JSON_ENCRYPT', true),
];

When i put GOOGLE_ALLOW_JSON_ENCRYPT = true

I'm getting this error message => Illuminate\Contracts\Encryption\DecryptException The payload is invalid. (View: C:\Users\Reda\Desktop\Newsletter\resources\views\welcome.blade.php)

When i put GOOGLE_ALLOW_JSON_ENCRYPT = false

The app working fine and also Google OAuth, but nothing happened i can't get the user access

this my code

Controller:

$messages = LaravelGmail::message()->subject('test')->all();
return view('test', compact('messages'));

Blade:

starting test

@foreach($messages as $message)
    <p>{{$message->getHtmlBody()}}</p>
    <p>{{$message->getSubject()}}</p>
@endforeach

but 'im getting this error => No credentials found.

0 likes
13 replies
laracoft's avatar

@redataha

Is gmail-json.json supposed to be in storage/app/gmail/tokens? Or beside .env?

redataha's avatar

this is what i found in the documentation of the package

If you're getting the Login Required error, try creating the gmail-json.json file under /storage/app/gmail/tokens/.
laracoft's avatar

You already specified GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET, I think just set GOOGLE_ALLOW_JSON_ENCRYPT=false.

When you say nothing happened, it might be due to other issues.

Please also remove your ID and SECRET from this post. Security issue for you.

redataha's avatar

When i make it false i got this error

No credentials found.
laracoft's avatar

Add your credentials in your .env file

GOOGLE_PROJECT_ID=...
GOOGLE_CLIENT_ID=...
GOOGLE_CLIENT_SECRET=...
laracoft's avatar

Ok, what do you think is the problem then?

redataha's avatar

Maybe the token, we need to store it in the JSON file

laracoft's avatar

Your token already in the JSON file. Download your token again from Google. It might be corrupted.

redataha's avatar

I don't know wich json file you are talking about !

laracoft's avatar

...

  1. What is inside your gmail-json.json file?
  2. Where did you get gmail-json.json in the first place?
redataha's avatar

I create it by myself, it empty ! like the documentation said

https://github.com/dacastro4/laravel-gmail#login-required

Please or to participate in this conversation.