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 8356867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:18:32+00:00 2026-06-09T10:18:32+00:00

How will I know if my access token has expired. I’m using try and

  • 0

How will I know if my access token has expired.

I’m using try and catch

try {
$result = file_get_contents('https://www.googleapis.com/calendar/v3/calendars/primary/events?access_token='.$accesstoken);
print_r($result);
}
catch(Exception $e){
echo "Get new token";
}

but still it gets error from the file_get_contents then prints “Get new token”

If I want to use curl

$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,'https://www.googleapis.com/calendar/v3/calendars/primary/events?access_token='.$accesstoken);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);

then what should I do to catch the error here?

//if error because access token is invalid,
  do here

// my fixed solution

 $response= json_decode($result);
 if($response->error){ // if result has errors
   echo "Get new token";
 }
  • 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-09T10:18:33+00:00Added an answer on June 9, 2026 at 10:18 am

    probing this url:

    https://www.googleapis.com/oauth2/v1/tokeninfo?access_token={accessToken}
    

    will gives you:

    {
      "audience":<your_client_id>,
      "user_id":<user_id_if_userinfo.profile_was_authorized>,
      "scope":"<authorized_scope_1> <authorized_scope_1>",
      "expires_in":<time_to_live>
    }
    

    or an error:

    {"error":"invalid_token"}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using SQL Server for my web application. How will I know that
I know i will get this exception when i try to modify or remove
People familiar with Homographies will know that you have to normalize it dividing by
Occasionally I will know that there is a .NET Framework function that returns a
How will I know if jquery slider is at the end of the scroll?
I have an ICollection that I know will only ever have one member. Currently,
I am trying in javascript to convert an integer (which I know will be
When an Iframe is loading, hlow will I know when it is complete and
I know it will sound dumb or people will just say: read the documentations
I know this will let the user retrieve the latest 10 posts from cocacola

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.