Google Workspace显示:未找到 404

huangapple go评论52阅读模式
英文:

Google workspace shows: Not Found 404

问题

I am using Google Workspace to manage my calendars:

And I have this code to try and access it:

$calendar_id = "***********@resource.calendar.google.com";
$client = new \Google_Client();
$client->setAuthConfig(storage_path('app/google-calendar/service-account-credentials.json'));
$client->addScope(\Google_Service_Calendar::CALENDAR);

// list all events
$service = new \Google_Service_Calendar($client);
$results = $service->events->listEvents($calendar_id);

return $results;

But, I am getting this error:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "notFound",
    "message": "Not Found"
   }
  ],
  "code": 404,
  "message": "Not Found"
 }
}

Any ideas?

英文:

I am using google workspace to mange my calanders:

And I have this code to try and access it:

    $calendar_id = "***********@resource.calendar.google.com";
    $client = new \Google_Client();
    $client->setAuthConfig(storage_path('app/google-calendar/service-account-credentials.json'));
    $client->addScope(\Google_Service_Calendar::CALENDAR);

    // list all events
    $service = new \Google_Service_Calendar($client);
    $results = $service->events->listEvents($calendar_id);

    return $results;

But, I am getting this error:

"{\n \"error\": {\n  \"errors\": [\n   {\n    \"domain\": \"global\",\n    \"reason\": \"notFound\",\n    \"message\": \"Not Found\"\n   }\n  ],\n  \"code\": 404,\n  \"message\": \"Not Found\"\n }\n}\n"

Any ideas?

答案1

得分: 0

以下是翻译好的内容:

"这里缺少的是应该访问的日历,您可以添加以下行来实现这一点(该行摘自此答案,那里还有更多代码,但下面的行是您的代码中唯一缺少的部分)

$client->setSubject(
            subject: "在这里,您必须输入您的Google Workspace帐户用户名"
        );

之所以会收到“未找到”的错误消息,是因为服务帐户本身试图显示它自己的日历,但服务帐户没有可显示的日历,这就是您没有收到任何其他类型的错误消息的原因。

希望这有所帮助!"

英文:

What's missing here is the calendar that is supposed to be accessed, you can add the line below to achieve this (The line was taken from this answer, there is also a lot more code there but the line below is the only thing missing from your code)

$client->setSubject(
            subject: "Here, you have to enter your Google Workspace Account Username"
        );

The reason why you get the "Not found" error message is because the service account itself was trying to show it's own calendar however service accounts do not have a calendar to show and that's why you don't get any other type of error message.

Hope this helps!

huangapple
  • 本文由 发表于 2023年5月17日 18:45:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76271249.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定