0

I am getting error when calling google sign in API. Error is

"Legacy People API has not been used in project ************ before or it is disabled"

But the people API is enable. How to solve this error ?

This is my google api url is this is sufficient to solve my problem

if (empty($_POST['google_key'])) {
        $error_code    = 5;
        $error_message = 'google_key (POST) is missing';
    } else {
        $app_key = $_POST['google_key'];
        // https://www.googleapis.com/plus/v1/people/me?access_token={$access_token}&key={$app_key}
        $get_user_details = fetchDataFromURL("https://people.googleapis.com/v1/people/me?access_token={$access_token}&key={$app_key}");
        $json_data = json_decode($get_user_details);
        if (!empty($json_data->error)) {
            $error_code    = 4;
            $error_message = $json_data->error;
        } else if (!empty($json_data->id)) {
            $social_id = $json_data->id;
            $social_email = $json_data->emails[0]->value;
            $social_name = $json_data->displayName;
            if (empty($social_email)) {
                $social_email = 'go_' . $social_id . '@google.com';
            }
        }
    }

this is my code where m using app key as google key and the access token now explain me where's the problem

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
vainu
  • 131
  • 1
  • 12
  • Does this answer your question? [403 Message: Legacy People API has not been used in project](https://stackoverflow.com/questions/58645078/403-message-legacy-people-api-has-not-been-used-in-project) – Christoph Aug 30 '21 at 07:56
  • @Christoph this question is tagged PHP which implies the author is using php the duplicate you are mentioning is C#. Do you still think its a duplicate? – Linda Lawton - DaImTo Aug 30 '21 at 08:56
  • 1
    Please edit your question and include [example] specifically your authorization code and the method you are trying to call. – Linda Lawton - DaImTo Aug 30 '21 at 08:57
  • @DaImTo I did a quick research and as far as I can tell this problem is specific to the API, not to the programming language. It's more about using the correct endpoints than implementing them. The answers in the linked questions are not specific to c# either, so I figured it might be a duplicate. – Christoph Aug 30 '21 at 09:22
  • When editing your question dont remove the existing text that changes the context of the question. If you have a new question open a new question. – Linda Lawton - DaImTo Aug 30 '21 at 12:26
  • Why are you not following the official [PHP quickstart](https://developers.google.com/people/quickstart/php) ? I cant tell you where you are getting that access token from the API key should be comming from the google cloud console when you created your project. – Linda Lawton - DaImTo Aug 30 '21 at 12:26

1 Answers1

3

The trick here is that it says legacy people api, this often means you are trying to use one of the old Google+ scopes.

A lot of the profile related endpoints that where once part of the google+ api were moved to the People api after the shutdown of Google+ .

As you can see by the endpoint you are calling you are trying to use the old google+ endpoint which was shutdown years ago.

googleapis.com/plus/v1

You should be using people.get

The correct endpoint would be.

GET https://people.googleapis.com/v1/{resourceName=people/*}

People API scopes

These are the new scopes for the people api.

enter image description here

Enable people api

The first thing you need to do is double check the Client id and the project you are using. Are in fact the same as the one you think it is.

Then go to Google cloud console for that project. Click library

enter image description here

In the search box search for people

enter image description here

And select people api

Then click enable

enter image description here

Once it has been enable in the same project as the client id you are using it should work within a few minutes.

PHP code

Assuming you are following the PHP quick start something like the following should give you the response you are looking for.

 $results = $service->people->get('people/me');
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • already enabled google people api but not getting resonse – vainu Aug 30 '21 at 09:47
  • 2
    Please edit your question and include your code. If you are getting that error message your doing something else wrong or your checking the wrong client id. – Linda Lawton - DaImTo Aug 30 '21 at 09:51
  • @Dalmto "https://www.googleapis.com/plus/v1/people/me?access_token={$access_token}&key={$app_key}" this is my google api url is this is sufficient to solve my problem – vainu Aug 30 '21 at 09:58
  • Theres your problem that endpoint was for Google+ as I mentioned. You should use [People.get](https://developers.google.com/people/api/rest/v1/people/get) which would be https://people.googleapis.com/v1/people/me. Please check the edit on my anwser – Linda Lawton - DaImTo Aug 30 '21 at 10:28
  • with "https://people.googleapis.com/v1/people/me" this url am getting error { "error": { "code": 403, "message": "The request is missing a valid API key.", "status": "PERMISSION_DENIED" } } can u explane what is the API KEY > – vainu Aug 30 '21 at 11:43
  • did you add the access token and the api key like you had on your original request? You know it would help a lot if you would post your code in your question. change **googleapis.com/plus/v1/people/me** to **people.googleapis.com/v1/people/me** in your call. All you are doing is pointing to a different endpoint. You still need to be authorized. – Linda Lawton - DaImTo Aug 30 '21 at 12:11
  • Please check the update on my answer. I have include the code you should be using assuming that you are using the PHP client library. – Linda Lawton - DaImTo Aug 30 '21 at 12:19
  • first i post my code, secound thing is am not getting what is the api key which key i place inside the api key can u explane something ? – vainu Aug 30 '21 at 12:20
  • "googleapis.com/plus/v1/people/me?access_token={$access_token}&key={$app_key}" <--- its the code you gave me that you said you where using it. The access token and key you where sending before. – Linda Lawton - DaImTo Aug 30 '21 at 12:21
  • The answer to your question is that you where using the wrong endpoint. I have answered that question and you should be all set now. I think you should take a step back and have a look at the official sample. https://developers.google.com/people/quickstart/php If you have any issues you should open a new question. – Linda Lawton - DaImTo Aug 30 '21 at 12:30