JavaEar 专注于收集分享传播有价值的技术资料

未捕获的TypeError:无法读取未定义的属性" 用户" (Uncaught TypeError: Cannot read property 'users' of undefined)

I am using Gmail API to Send Email. but getting an error:

Uncaught TypeError: Cannot read property 'users' of undefined

<script type="text/javascript">

    function sendMessage(email, callback) {
        // Web-safe base64 
        var base64EncodedEmail = btoa(email).replace(/\//g, '_').replace(/\+/g, '-');
        var request = gapi.client.gmail.users.messages.send({
            'userId': 'me',
            'message': {
                'raw': base64EncodedEmail
            }
        });
        request.execute(callback);
    }

    function send() {


        var to = 'vijay@itsabacus.com',
         subject = 'Hello World',

         content = 'send a Gmail.'
        var email = "From: 'me'\r\n" +
            "To:  " + to + "\r\n" +
            "Subject: " + subject + "\r\n" +
            "\r\n" +
            content;
            sendMessage(email, function () {
            console.log(arguments);
        });
    }
</script>

1个回答

    最佳答案

  1. 英文原文

    I hit the same issue and for me I needed to do something like the following:

    gapi.load('client:auth2', () => {
        gapi.client.load('gmail', 'v1', () => {
          console.log('Loaded Gmail');
        });
    }
    

    After that in the debugger I could use the gmail api as you have above:

    gapi.client.gmail.users.messages.send({...});
    

    Hope this helps.


    中文翻译

    我遇到了同样的问题,对我来说,我需要做类似以下的事情:

      gapi.load('client:auth2',()=&gt; {
        gapi.client.load('gmail','v1',()=&gt; {
          console.log('加载Gmail');
        });
    }
     

    之后在调试器中我可以像上面一样使用gmail api:

      gapi.client.gmail.users.messages.send({...});
     

    希望这有帮助。

    I hit the same issue and for me I needed to do something like the following:

    gapi.load('client:auth2', () => {
        gapi.client.load('gmail', 'v1', () => {
          console.log('Loaded Gmail');
        });
    }
    

    After that in the debugger I could use the gmail api as you have above:

    gapi.client.gmail.users.messages.send({...});
    

    Hope this helps.

    我遇到了同样的问题,对我来说,我需要做类似以下的事情:

      gapi.load('client:auth2',()=&gt; {
        gapi.client.load('gmail','v1',()=&gt; {
          console.log('加载Gmail');
        });
    }
     

    之后在调试器中我可以像上面一样使用gmail api:

      gapi.client.gmail.users.messages.send({...});
     

    希望这有帮助。