致命错误:未捕获的异常' Google_Service_Exception'

时间:2015-06-24 05:58:13

标签: gmail-api

我创建了一个函数,通过使用CodeIgniter(PHP Framework)从我自己的Gamil帐户中检索消息。我试图遵循stackOverlow的一些建议,但仍然没有完成。所以代码要求我登录并显示致命错误:未捕获异常Google_Service_Exception

你能告诉我什么是真正的问题吗?你能指引我找正确的代码吗?

        $this->load->library('google');
        $client = new Google_Client();
        $client->setClientId('000000-00000000000.apps.googleusercontent.com');
        $client->setClientSecret('0000-0000000@developer.gserviceaccount.com');
        $client->setRedirectUri(base_url('manage-reservation/get_mess'));
        $client->addScope('email');
        $client->addScope('profile');     
        $client->addScope('https://mail.google.com');           
        $client->setAccessType('offline');
        //$client->setAccessToken($_SESSION['oauth_access_token']);

        //$client->setDeveloperKey('1052192456244-qjjb1unv7rolpg0gmm0p98osv7lpsqo9@developer.gserviceaccount.com');
        //$client->setApprovalPrompt('auto');

        $service = new Google_Service_Gmail($client);

       $optParams = [];
        $optParams['maxResults'] = 5; // Return Only 5 Messages
        $optParams['labelIds'] = 'INBOX'; // Only show messages in Inbox
        $messages = $service->users_messages->listUsersMessages('me',$optParams);
        $list = $messages->getMessages();
        $messageId = $list[0]->getId(); // Grab first Message


        $optParamsGet = [];
        $optParamsGet['format'] = 'full'; // Display message in payload
        $message = $service->users_messages->get('me',$messageId,$optParamsGet);
        $messagePayload = $message->getPayload();
        $headers = $message->getPayload()->getHeaders();
        $parts = $message->getPayload()->getParts();

        $body = $parts[0]['body'];
        $rawData = $body->data;
        $sanitizedData = strtr($rawData,'-_', '+/');
        $decodedMessage = base64_decode($sanitizedData);

        var_dump($decodedMessage);

出现错误:

  

致命错误:未捕获的异常' Google_Service_Exception'同   消息'调用GET时出错   https://www.googleapis.com/gmail/v1/users/me/messages?maxResults=5&labelIds=INBOX:   (401)需要登录'在   C:\ XAMPP \ htdocs中\主机\制作的Airbnb邮件管理的\代码的应用程序\ THIRD_PARTY \谷歌\ HTTP \ REST.php:110   堆栈跟踪:#0   C:\ XAMPP \ htdocs中\主机\制作的Airbnb邮件管理的\代码的应用程序\ THIRD_PARTY \谷歌\ HTTP \ REST.php(62):   Google_Http_REST :: decodeHttpResponse(对象(Google_Http_Request)   对象(Google_Client))#1 [内部函数]:   Google_Http_REST :: doExecute(对象(Google_Client)   对象(Google_Http_Request))#2   C:\ xampp \ htdocs \ host \ airbnb-mail-manage \ code-application \ third_party \ Google \ Task \ Runner.php(174):call_user_func_array(Array,Array)#3   C:\ XAMPP \ htdocs中\主机\制作的Airbnb邮件管理的\代码的应用程序\ THIRD_PARTY \谷歌\ HTTP \ REST.php(46):   Google_Task_Runner-> run()#4   C:\ XAMPP \ htdocs中\主机\制作的Airbnb邮件管理的\代码的应用程序\ THIRD_PARTY \谷歌\ Client.php(593):   Google_Http_REST ::执行(对象(Google_Client)   对象(Google_Http_Request))#5 C:\ in   C:\ XAMPP \ htdocs中\主机\制作的Airbnb邮件管理的\代码的应用程序\ THIRD_PARTY \谷歌\ HTTP \ REST.php   在线110

0 个答案:

没有答案