Я получаю следующую ошибку, когда отправляю запрос в API Google, используя игровую площадку Google Oauth, а также выполняю код с помощью функции cUrl в коде php.
Несанкционированный канал обратного вызова WebHook: "https://example.com/". Получение кода ошибки 401 по причине" push.webhookUrlUnauthorized "
$url = sprintf("https://www.googleapis.com/calendar/v3/calendars/%s/events/watch",$calenderId );
/* setup the POST parameters */
$fields = json_encode(array(
'id' => "01234567-89ab-cdef-0123456789ab",
'type' => "web_hook",
'address' => "https://example.com/"
));
echo $fields;exit;
/* setup POST headers */
$headers[] = 'Content-Type: application/json';
$headers[] = 'Authorization: Bearer ' . 'auth_token_for_current_user';
/* send POST request */
$channel = curl_init();
curl_setopt($channel, CURLOPT_HTTPHEADER, $headers);
curl_setopt($channel, CURLOPT_URL, $url);
curl_setopt($channel, CURLOPT_RETURNTRANSFER, true);
curl_setopt($channel, CURLOPT_POST, true);
curl_setopt($channel, CURLOPT_POSTFIELDS, $fields);
curl_setopt($channel, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($channel, CURLOPT_TIMEOUT, 3);
$response = curl_exec($channel);
Ожидаемый результат:
{
"kind": "api#channel",
"id": "01234567-89ab-cdef-0123456789ab"", // ID you specified for this channel.
"resourceId": "o3hgv1538sdjfh", // ID of the watched resource.
"resourceUri": "https://www.googleapis.com/calendar/v3/calendars/my_calendar@gmail.com/events", // Version-specific ID of the watched resource.
"token": "target=myApp-myCalendarChannelDest", // Present only if one was provided.
"expiration": 1426325213000, // Actual expiration time as Unix timestamp (in ms), if applicable.
}
Фактические результаты:
Www-authenticate: Bearer realm="https://accounts.google.com/", error=invalid_token
{
"error": {
"code": 401,
"message": "Unauthorized WebHook callback channel: https://example.com/",
"errors": [
{
"domain": "global",
"message": "Unauthorized WebHook callback channel: https://example.com/",
"reason": "push.webhookUrlUnauthorized"
}
]
}
}