Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8504671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:06:04+00:00 2026-06-11T02:06:04+00:00

I have activated the google API console https://code.google.com/apis/console and I’ve created a project, including

  • 0

I have activated the google API console https://code.google.com/apis/console and I’ve created a project, including the OAuth credentials. I’ve chosen the “desktop application” setting, since this app is going to run outside of the browser, from the CLI (and actually only on my computer).

I have also downloaded the client library as described here: https://code.google.com/p/google-api-php-client/.

I have edited google-api-php-client/src/config.php editing the keys application_name, oauth2_client_id, oauth2_client_secret, oauth2_redirect_uri and developer_key and nothing else.

I have deleted all other services from services too.

Now, I have the following app, put together from the samples in the guide:

<?php
require_once 'google-api-php-client/src/apiClient.php';
require_once "google-api-php-client/src/contrib/apiCalendarService.php";

session_start();

$apiClient = new apiClient();
$apiClient->setUseObjects(true);
$service = new apiCalendarService($apiClient);


if (isset($_SESSION['oauth_access_token'])) {
  $apiClient->setAccessToken($_SESSION['oauth_access_token']);
} else {
  $token = $apiClient->authenticate();
  $_SESSION['oauth_access_token'] = $token;
}

$event = new Event();
$event->setSummary('Appointment');
$event->setLocation('Somewhere');
$start = new EventDateTime();
$start->setDateTime('2011-06-03T10:00:00.000-07:00');
$start->setTimeZone('America/Los_Angeles');
$event->setStart($start);
$end = new EventDateTime();
$end->setDateTime('2011-06-03T10:25:00.000-07:00');
$end->setTimeZone('America/Los_Angeles');
$event->setEnd($end);
$event->setRecurrence(array('RRULE:FREQ=WEEKLY;UNTIL=20110701T100000-07:00'));
$attendee1 = new EventAttendee();
$attendee1->setEmail('attendeeEmail');
// ...
$attendees = array($attendee1,
                   // ...
                   );
$event->attendees = $attendees;
$recurringEvent = $service->events->insert('primary', $event);

echo $recurringEvent->getId();

However I’m getting the following error:

Fatal error: Uncaught exception 'apiServiceException' with message 'Error calling POST https://www.googleapis.com/calendar/v3/calendars/primary/events?key=<the-key>: (401) Login Required' in /home/flav/projects/.../google-api-php-client/src/io/apiREST.php on line 86

apiServiceException: Error calling POST https://www.googleapis.com/calendar/v3/calendars/primary/events?key=<the-key>: (401) Login Required in /home/flav/projects/.../google-api-php-client/src/io/apiREST.php on line 86

Call Stack:
    0.0003     252600   1. {main}() /home/flav/projects/.../gcal-api.php:0
    0.0202    1769344   2. EventsServiceResource->insert() /home/flav/projects/.../gcal-api.php:38
    0.0202    1770288   3. apiServiceResource->__call() /home/flav/projects/.../google-api-php-client/src/contrib/apiCalendarService.php:493
    0.0206    1781864   4. apiREST::execute() /home/flav/projects/.../google-api-php-client/src/service/apiServiceResource.php:187
    0.2342    1794848   5. apiREST::decodeHttpResponse() /home/flav/projects/.../google-api-php-client/src/io/apiREST.php:56

How to fix this?

Oh, and on the google API console, I have two values for Redirect URIs:, urn:ietf:wg:oauth:2.0:oob and http://localhost, which one should I use for oauth2_redirect_uri?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T02:06:05+00:00Added an answer on June 11, 2026 at 2:06 am

    I think this can be caused by several things. my 2 cents:

    Do you have several calendars registered? Maybe your calendar which you’d like to insert events into isn’t the “primary” (=default?) calendar (or your Oauth cred data refer to a different calendar).
    If so, replace this line

    $service->events->insert('primary', $event);
    

    with

    $calendar_id = "somelongstring@group.calendar.google.com"; //look this up from calendar /settings calendar details settings page at the bottom
    $service->events->insert($calendar_id, $event);
    

    The calendar id is a bit hard to find…look it up. You can find it, for example, on your google account home page /calendar /gear symbol /settings / click calendar-name / calendar details settings page, at the bottom.

    My redirect url (for a web app, though) points to the .php page that issued the oauth request. If authenticated I define another redirect, this time my own. Confusing? yes, but it works for me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using http://code.google.com/p/django-email-extras/ to generate rich email content. I have trouble in sending email
Here's my URL: https://maps.googleapis.com/maps/api/place/search/xml?location;=41.983333,-87.766666&radius;=5000&sensor;=false&type;=doctor&name;=DPM&key;= mykey I get a request denied response. I have activated
I have activated the IIS package for windows, and, I created an index.html file
I have a question with regards Google Code svn repositories. Is there a way
I have a really bad conflict with using google-webfonts. OK here is the code:
I have used this: Generate Google Analytics events (__utm.gif requests) serverside and this: http://www.garyrgilbert.com/blog/index.cfm/2008/10/21/Tracking-Digital-Content
while running: rake snorby:setup getting below error: rake aborted! You have already activated rake
I have a java method activated by a mouse click on a button private
I have a bash script activated by crontab and running in background. I would
Currently have a drop down menu that is activated on a hover (from display:none

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.