更新Google事件时出错

时间:2015-03-11 11:51:07

标签: google-calendar-api google-api-php-client

我正在尝试更新谷歌日历活动,但它不能使用默认日历..我的意思是当我使用“主要”默认日历时,它不起作用 这是我的代码

const USER_EVENT_TYPE='primary';
const CLASS_EVENTS='Events';
 if ($googleClient->getAccessToken())
        {
            if(!class_exists(self::CLASS_EVENTS))
            {
                $includeApplicationFiles=Mage::getBaseDir(self::LIBRARY_PATH);
                foreach (glob($includeApplicationFiles.self::INCLUDE_ALL_FILES) as $retrieveFiles)
                {
                    include $retrieveFiles;
                }
                $allCalendarEvents = $googleCalendar->events->listEvents(self::USER_EVENT_TYPE);
                foreach ($allCalendarEvents->getItems() as $getSingleEvent) {
                    if($selectedEventValue==$getSingleEvent->summary)
                    {
                        $getSingleEvent->setSummary($selectedEventValue);
                        $addEventGuests = new Google_EventAttendee();
                        $addEventGuests->setEmail($selectGuestValue);
                        $invitedGuests = array($addEventGuests);
                        $getSingleEvent->attendees = $invitedGuests;
                        $updatedEvent = $googleCalendar->events->update(self::USER_EVENT_TYPE, $getSingleEvent->getId(),$getSingleEvent);
                    }
                }
            }
        }

有这样的错误

<br />
<b>Fatal error</b>:  Uncaught exception 'Google_ServiceException' with message 'Error calling PUT https://www.googleapis.com/calendar/v3/calendars/primary/events/5vmet3i6mmak81utnj2p0ebv8g?key=900220817963%40developer.gserviceaccount.com: (403) Forbidden' in C:\xampp\htdocs\magento\lib\google-api-php-client\src\io\Google_REST.php:61
Stack trace:
#0 C:\xampp\htdocs\magento\lib\google-api-php-client\src\io\Google_REST.php(35): Google_REST::decodeHttpResponse(Object(Google_HttpRequest))
#1 C:\xampp\htdocs\magento\lib\google-api-php-client\src\service\Google_ServiceResource.php(152): Google_REST::execute(Object(Google_HttpRequest))
#2 C:\xampp\htdocs\magento\lib\google-api-php-client\src\contrib\Google_CalendarService.php(591): Google_ServiceResource-&gt;__call('update', Array)
#3 C:\xampp\htdocs\magento\app\code\local\Social\Google\Model\Google.php(360): Google_EventsServiceResource-&gt;update('primary', '5vmet3i6mmak81u...', Object(Google_Event))
#4 C:\xampp\htdocs\magento\Connectors\google\AutoCompleteCalendarEvents.php(16): Social_Goog in <b>C:\xampp\htdocs\magento\lib\google-api-php-client\src\io\Google_REST.php</b> on line <b>61</b><br />

1 个答案:

答案 0 :(得分:0)

如果没有看到您的所有代码,我会提出两点建议:

您可以在开发者控制台中更新密钥并检查设置。如果您更改了项目命名空间并使用了相同的密钥,则可能会出现问题。

另一件事是,如果您将开发人员密钥设置在任何位置以删除:

$googleClient->setDeveloperKey('insert_key');

如果您阅读了以下链接,则会显示一系列类似的问题。

https://code.google.com/p/google-api-php-client/issues/detail?id=218

我应该补充一点,403 Forbidden表示您正在与服务器成功通信,但您缺少该操作/操作的权限。
这就是为什么它倾向于:
1.密钥无效,或
2.如果密钥有效,并且您已覆盖代码中的有效密钥值。从而呈现一个新值,当然这是一个无效的密钥。

如果您需要更多帮助,请与我联系。