google-calendar-api - 更新谷歌事件时出错

标签 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 />

最佳答案

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

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

另一件事是,如果您在任何地方设置了开发人员 key 以删除它:

$googleClient->setDeveloperKey('insert_key');

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

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

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

如果您需要更多帮助,请告诉我。

关于google-calendar-api - 更新谷歌事件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28985901/

相关文章:

google-api - 如何构建使用谷歌日历 api 的 web 应用程序而无需验证?

java - 使用发布请求在 Google 日历中创建新事件

javascript - 如何使用 CSS 自定义 Google 日历?

javascript - 在新的 Date() 中指定 Olson ID

google-api - 使用谷歌翻译 api 的值无效 (400)

c# - Google API Where() 和 When() 命名空间

google-api - 带有 PHP 客户端 2.0 的 Google Drive API V3 - 在单个请求中下载文件内容和元数据

php - Google API 刷新 token

php - 错误 "(get) unknown parameter: ' personFields'"遵循 Google People API 文档中的示例时

php - 无法使用Google PHP客户端库通过YouTube API设置水印