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

  • SEARCH
  • Home
  • 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 7945899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:59:54+00:00 2026-06-04T00:59:54+00:00

I thought this one was going to be a breeze. Hence I’m stuck at

  • 0

I thought this one was going to be a breeze. Hence I’m stuck at the very beginning 🙁

I created a Google Calendar where users can add events using a ‘shared’ dedicated login.
Then I need to write a PHP script on my server to read the events in a given time frame.

I thought the API key described here would be enough. But it’s not.

 curl https://www.googleapis.com/calendar/v3/users/me/calendarList?key=mykey

says Login required.

So I read about OAuth2.0 and how I need user to authenticate. The problem is my script is not interactive (although hardcoding the login in the script is not a problem to me: The info is not life-critical). So I read about Service Accounts but it looks like it’s for non-user info.

Question: How do I code my script to force a given login without involving a human?

Note: This SO question seemed promising but the answer is for API version 2.0, which seems obsoleted.

  • 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-04T00:59:56+00:00Added an answer on June 4, 2026 at 12:59 am

    The first thing you need to do is obtain an access token. This will require a human.
    Assuming you’re using the Google APIs PHP Client, it can be done with this script (run from the command line).

    NOTE: The snippet below works with a Client ID for Installed Applications. Make sure you create a client ID of this type in the Google API Access console.

    require_once '../../src/apiClient.php';
    defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
    
    $client = new apiClient();
    // Visit https://code.google.com/apis/console to create your client id and cient secret
    $client->setClientId('INSERT_CLIENT_ID');
    $client->setClientSecret('INSERT_CLIENT_SECRET');
    $client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
    $client->setScopes(array(
        'https://www.googleapis.com/auth/calendar',
        'https://www.googleapis.com/auth/calendar.readonly',
    ));
    
    $authUrl = $client->createAuthUrl();
    
    print "Please visit:\n$authUrl\n\n";
    print "Please enter the auth code:\n";
    $authCode = trim(fgets(STDIN));
    
    $_GET['code'] = $authCode;
    $token = $client->authenticate();
    var_dump($token);
    

    This will give you a json encoded string containing your accessToken and refreshToken. The accessToken expires after 1 hour, but don’t worry. The refreshToken will not expire (unless you uninstall the application), and can be used to obtain a new refreshToken. The client library takes care of this part.

    Next, save the full json string token (not only the access_token property in a safe place and make sure it can’t be read by others. Your app can then call $client->setAccessToken($token) where $token was looked up from the safe location (Again, $token is the full json-encoded string, not limited to its access_token property).

    Now, you can make authenticated request to the Calendar APIs!

    require_once '../../src/apiClient.php';
    require_once '../../src/contrib/apiCalendarService.php';
    session_start();
    
    $client = new apiClient();
    $client->setApplicationName("Google Calendar PHP Sample Application");
    $cal = new apiCalendarService($client);
    
    $client->setAccessToken($tokenFromSafePlace);
    
    $calList = $cal->calendarList->listCalendarList();
    print "<h1>Calendar List</h1><pre>" . print_r($calList, true) . "</pre>";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't seem to figure this one out by searching Google. I have an
I know this one is going to be a long-shot, but I thought I'd
I would have thought this one would be simple but I'm trying to change
I thought this would be fairly easy, but I'm totally baffled. I want one
Before I throw something ugly together I thought this would be a good one
My brain is fried, so I thought I would pass this one to the
When this quick one hour project came up I never thought that 2 days
Strange one this, which isn't programming related directly, but I thought it important to
This is a thought problem, and one I have been wrestling with for about
This is an odd one. I added a file to a project, thought I

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.