2
votes

I am trying to implement the google-api-php-client. I chose the "User Query - Retrieving An Id Token" from the list, which brings up the Connect Me! button. After pressing the Allow button on the next page, the following error is issued:

'Google_Exception' with message 'Invalid client secret JSON file'

I have read similar SO questions, but none of the solutions worked for me or seemed too complicated to implement.

I generated the JSON file using the "OAuth client id" credentials option, which produces the following and looks correct to me.

{
    "web": {
        "client_id": "904891570762-e6l415d7ms8eh8amq8lb95550jk6277r.apps.googleusercontent.com",
        "project_id": "writers-tryst",
        "auth_uri": "https://accounts.google.com/o/oauth2/auth",
        "token_uri": "https://accounts.google.com/o/oauth2/token",
        "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
        "client_secret": "my-secret",
        "redirect_uris": [
            "http://localhost:16743/google-api-php-client/examples/oauth2callback.php"
        ],
        "javascript_origins": [
            "http://writers-tryst.com",
            "http://writers-tryst.ron-tornambe.com"
        ]
    }
}

The error is generated from the following code snippet:

$data = json_decode($json);
$key = isset($data->installed) ? 'installed' : 'web';
if (!isset($data->$key)) {
  throw new Google_Exception("Invalid client secret JSON file.");
}

Has anyone encountered the same problem? Is there a work-around for this?

1

1 Answers