Create Simple Google Calendar Event in PHP

前端 未结 2 1579
时光取名叫无心
时光取名叫无心 2020-12-17 04:52

I\'m having a heck of a time trying to get a very simple event added to a calendar using the Google Calendar API, and I would love it if someone could point out my (probably

2条回答
  •  情深已故
    2020-12-17 05:29

    The last portion of your code isn't using correct logic. The crux of the problem is with if (!$client->getAccessToken()). This statement, in the context of your sample code, roughly translates to: If you fail to get the access token, create the event. Obviously this is not what you want to happen. ;)

    Instead try this:

    if ($client->getAccessToken()){
        //succeeded in getting an access token, so create and insert the event
    } else {
        $authUrl = $client->createAuthUrl();
        //failed to get an access token, so display $authurl as a link to open the auth window
    }
    

提交回复
热议问题