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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:39:59+00:00 2026-05-27T21:39:59+00:00

I used Facebook login to identify users. When a new user comes, I store

  • 0

I used Facebook login to identify users. When a new user comes, I store their userID in my database. Next time they come, I recognized their Facebook ID and I know which user it is in my database.

Now I am trying to do the same with Google’s OAuth2, but how can I recognize the users?

Google sends me several codes and tokens (access_token, id_token, refresh_token), however none of them are constant. Meaning if I log out and log back in 2 minutes later, all 3 values have changed. How can I uniquely identify the user?

I am using their PHP client library: https://code.google.com/p/google-api-php-client/

  • 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-05-27T21:40:00+00:00Added an answer on May 27, 2026 at 9:40 pm

    I inserted this method into google-api-php-client/src/apiClient.php:

    public function getUserInfo() 
    {
        $req = new apiHttpRequest('https://www.googleapis.com/oauth2/v1/userinfo');
        // XXX error handling missing, this is just a rough draft
        $req = $this->auth->sign($req);
        $resp = $this->io->makeRequest($req)->getResponseBody();
        return json_decode($resp, 1);  
    }
    

    Now I can call:

    $client->setAccessToken($_SESSION[ 'token' ]);
    $userinfo = $client->getUserInfo();
    

    It returns an array like this (plus e-mail if that scope has been requested):

    Array
    (
        [id] => 1045636599999999999
        [name] => Tim Strehle
        [given_name] => Tim
        [family_name] => Strehle
        [locale] => de
    )
    

    The solution originated from this thread: https://groups.google.com/forum/#!msg/google-api-php-client/o1BRsQ9NvUQ/xa532MxegFIJ

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

Sidebar

Related Questions

I've used the php-sdk to perform the login using facebook. What should I store
I'm having a problem with a user logging in: 1) click facebook login button
I had used facebook login button in my website, is there any way to
I implemented a custom FB login button and used Facebook javascript SDK, so I
Previously i used the JavaScript API for Facebook Connect, so i had the fb:login-button
I'm using OmniAuth with Devise to allow users to login with facebook or to
I want to user facebooker2 for facebook connect functionality. So when the user login
I have used facebook to allow users to log into a site. The page
I have an app which user can login using twitter and facebook to login,
I use Facebook OAuth 2.0 to register new users to my website. After which

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.