0

我正在创建一个与 Google 日历交互的应用程序并希望观看资源,但我也希望能够停止观看它们。

当我尝试取消观看时,我得到了错误Error calling POST https://www.googleapis.com/calendar/v3/channels/stop: (403) Incorrect OAuth client

我正在使用服务帐户和 OAuth 2.0 对自己进行身份验证,并且绝对可以找到其他有效的 API 调用,因此我知道我已获得授权。我究竟做错了什么?

这些是一些有效的 API 调用......

public function getEvents($calendarId, $opts = array())
{
    $events = $this->calendarService->events->listEvents($calendarId, $opts);
    return $events;
}

public function getEvent($calendarId, $eventId)
{
    $event = $this->calendarService->events->get($calendarId, $eventId);
    return $event;
}

public function watch($calendarId, $channelId, $listener)
{
    $channel = new Google_Service_Calendar_Channel($this->client);
    $channel->setId($channelId);
    $channel->setType('web_hook');
    $channel->setAddress($listener);

    $watchEvent = $this->calendarService->events->watch($calendarId, $channel, array());
    return $watchEvent;
}

这是停止 API 调用...

public function stopWatch($channelId, $resourceId)
{
    $channel = new Google_Service_Calendar_Channel($this->client);
    $channel->setId($channelId);
    $channel->setResourceId($resourceId);

    $watchEvent = $this->calendarService->channels->stop($channel);
    return $watchEvent;
}

关于如何使它工作的任何想法?

4

1 回答 1

1

您需要从客户端实例化服务,然后从服务实例化通道。可能有一个快捷方式,但下面的代码有效。

$service = new Google_Service_Calendar($client);
$channel =  new Google_Service_Calendar_Channel($service);
$channel->setId($channelID);
$channel->setResourceId($ResourceID);

try
{
    $service->channels->stop($channel);
}
catch(Exception $e)
{   
    error_log("Caught exception in killWatch ",0);
}
于 2014-07-06T03:16:43.070 回答