google-api-php-client:无效的客户端机密JSON文件

问题描述:

似乎PHP的最新版本google-api-php-client与docs @ https://developers.google.com/drive/web/examples/php

Seems that the latest version of the google-api-php-client for PHP doesn't line up with the docs @ https://developers.google.com/drive/web/examples/php

在查看src代码时,我看到它正在寻找setAuthConfigFile()方法找不到的下载JSON中的密钥:在下载的JSON中不存在client_secret,已安装,web,redirect_uris(其他?). .仅存在private_key_id,private_key,client_email,client_id和类型.

Looking at the src code I'm seeing that it's looking for keys in the downloaded JSON that the setAuthConfigFile() method can't find: client_secret, installed, web, redirect_uris (others?) are not present in the downloaded JSON. Only private_key_id, private_key, client_email, client_id, and type are present.

代码和文档似乎真的杂乱无章,不同步...对于Google而言,这并不是第一个.最近有人使用该库让OAuth正常工作吗?

The code and docs seem really disorganized and out of sync... wouldn't be the first for Google. Has anyone gotten OAuth working recently using that library?

服务帐户" 网络应用" 之间的区别在于拨打电话到API.创建服务帐户"时,您将获得上述文件,即带有private_keyclient_emailclient_id等的JSON文件.

There is a difference between a "service account" and a "web apllication" to make calls to the API. When you created a "service account" you will get the file described above, a JSON file with private_key, client_email, client_id etc.

创建Web应用程序时,系统会为您提供client_idclient_secretredirect_uri等.

When you create a web application you will be given a client_id, client_secret, redirect_uri etc.

我建议阅读这些页面以选择所需的键和登录名(在两个页面上都找到将其集成到PHP中的示例):

I would suggest reading these pages to choose which key and login you need (on both pages you find examples to integrate it in PHP):

您可以使用PHP的Google API客户端库来创建网站 使用OAuth 2.0授权访问Google的服务器应用程序 蜜蜂. OAuth 2.0允许用户与 应用程序,同时保留其用户名,密码和其他 私人信息.例如,Web应用程序可以使用OAuth 2.0 获得用户的许可,以将文件存储在其Google云端硬盘中.

You can use the Google APIs Client Library for PHP to create web server applications that use OAuth 2.0 authorization to access Google APIs. OAuth 2.0 allows users to share specific data with an application while keeping their usernames, passwords, and other information private. For example, a web application can use OAuth 2.0 to obtain permission from users to store files in their Google Drives.

https://developers.google.com/api-客户端库/php/auth/web-app

通常,应用程序在应用程序使用服务帐户时 使用Google API来处理自己的数据,而不是用户的数据. 例如,使用Google Cloud Datastore来存储数据的应用程序 持久性将使用服务帐户来验证对其的调用 Google Cloud Datastore API.

Typically, an application uses a service account when the application uses Google APIs to work with its own data rather than a user's data. For example, an application that uses Google Cloud Datastore for data persistence would use a service account to authenticate its calls to the Google Cloud Datastore API.

https://developers.google.com/api-客户端库/php/auth/service-accounts