Error with Google Calendar API - 401 Login required when adding a calendar event
You are getting a 401 Login Required
because the second code is not setting the token:
$apiClient->setAccessToken($_SESSION['oauth_access_token']);
OAuth with Google won't work on a local environment. It needs to be a URL/IP address that Google servers can access for the callback / OAuth handshake.
Grab a domain and test it from there, or set up a forwarder with DynDNS or a similar service.