GithubHelp home page GithubHelp logo

Dacastro4\LaravelGmail\Services\Message\Mail::__construct(): Argument #1 ($message) must be of type ?Google_Service_Gmail_Message, Google\Service\Exception given about laravel-gmail HOT 6 OPEN

stefanofinetti avatar stefanofinetti commented on June 14, 2024
Dacastro4\LaravelGmail\Services\Message\Mail::__construct(): Argument #1 ($message) must be of type ?Google_Service_Gmail_Message, Google\Service\Exception given

from laravel-gmail.

Comments (6)

stefanofinetti avatar stefanofinetti commented on June 14, 2024 1

I've temporary solved the problem by disabling the preload function. It seems that Google consider as too many requests when you try to preload a whole inbox. This is unexpected behavior from google anyway.

from laravel-gmail.

umarzahid028 avatar umarzahid028 commented on June 14, 2024

Hi @stefanofinetti
I've been using this package for the last two years without any problems. However, today, I encountered the same error suddenly, and I'm unsure how to resolve it. When I remove the preload method, I get a different error. But if I use the take(50) method, it works, although it only returns 50 records. If you discover a proper solution, please inform me as my project is currently live.

Here's the code snippet:
$messages = LaravelGmail::message()->preload()->take(50)->after($last_email_sync_date)->all();

from laravel-gmail.

stefanofinetti avatar stefanofinetti commented on June 14, 2024

Hi @umarzahid028 , this is the snippet of code I'm using right now in a live production environment. We use multiple accounts so you'll find the user auth:

try {
$gmailUser = LaravelGmail::setUserId(Auth::user()->email);

        if ($gmailUser->check()) {

            $messages = $gmailUser->message()->in('INBOX')->all();
            $messaggi = collect($messages);

        } else {
            $messaggi = collect([]);
        }

        $msgPage = new LengthAwarePaginator($messaggi->forPage($request->page, 30), $messaggi->count(), 30, $request->page);
        $msgPage->withPath('/protocollo/posta');

        return view('protocollo.posta', [
            'messaggi' => $msgPage,
        ]);
    } catch (Exception $error) {
        Log::error('Errore accedendo a GMAIL', ['Data' => $error->getMessage()]);
        dd($error);
    }

The actual load of message is done after, in the view, in a foreach loop of all messages and for each call to $message i had to add ->load() before any other command:

$messaggio->load()->getLabels()
$messaggio->load()->->getFromName()

and so on.

This is just a workaround untile preload() will work again (hopefully)

from laravel-gmail.

umarzahid028 avatar umarzahid028 commented on June 14, 2024

Thank you for your reply.

When I use message()->in('INBOX')->all();, I encounter a "Call to a member function flatten() on null" error.

if ($message && $message->hasAttachments()) { // handle attachments }

from laravel-gmail.

stefanofinetti avatar stefanofinetti commented on June 14, 2024

That, i think, it's because you should use $message->load() && $message->load()->hasAttachments()) { // handle attachments }

Without ->load() you stil do not have the message object fully loaded to be used.

from laravel-gmail.

umarzahid028 avatar umarzahid028 commented on June 14, 2024

Thank you very much! ->load() method is also working for me. Once again, I appreciate you saving my time.

from laravel-gmail.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.