Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google api 如何让OAuth2使用服务帐户_Google Api_Oauth 2.0 - Fatal编程技术网

Google api 如何让OAuth2使用服务帐户

Google api 如何让OAuth2使用服务帐户,google-api,oauth-2.0,Google Api,Oauth 2.0,我们需要从旧的配置API迁移到新的管理SDK。问题是我们无法弄清楚如何让OAuth2使用服务帐户。我们使用以下代码作为示例,但无法确定key.p12文件是在何处/如何创建的。我在开发人员控制台中创建了一个服务帐户,其中包含cliendId、电子邮件地址和API密钥,并将应用程序绑定到我的服务器上。如果有人能帮助我理解如何创建key.p12文件,那么我很确定我能让它正常工作 谢谢 滑雪板 。。。 $key=file\u get\u内容(key\u文件); $client->setClientId(

我们需要从旧的配置API迁移到新的管理SDK。问题是我们无法弄清楚如何让OAuth2使用服务帐户。我们使用以下代码作为示例,但无法确定key.p12文件是在何处/如何创建的。我在开发人员控制台中创建了一个服务帐户,其中包含cliendId、电子邮件地址和API密钥,并将应用程序绑定到我的服务器上。如果有人能帮助我理解如何创建key.p12文件,那么我很确定我能让它正常工作

谢谢

滑雪板

。。。 $key=file\u get\u内容(key\u文件); $client->setClientId(客户端ID); $client->setAssertionCredentials(新的Google_AssertionCredentials( 服务\帐户\名称, 数组(“”), $key) );

请参阅-今天,谷歌云控制台的新版本实际上改变了这一点,但答案是最新的。

转到
选择您的项目
单击“API和身份验证”
单击“凭证”
单击“创建新客户端ID”
选择“服务帐户”
单击“创建客户端ID”
您的私钥将被下载。
您的公钥将存储并显示在控制台中。
您将无法再次检索私钥。谷歌只发送一次。如果丢失,则必须重新执行该过程,并更新应用程序中的相关设置。
如果这个问题已经回答,请将其标记为已回答

// Set your client id, service account name, and the path to your private key.
// For more information about obtaining these keys, visit:
// https://developers.google.com/console/help/#service_accounts
const CLIENT_ID = 'insert_your_client_id';
const SERVICE_ACCOUNT_NAME = 'insert_your_service_account_name';

// Make sure you keep your key.p12 file in a secure location, and isn't
// readable by others.
const KEY_FILE = '/super/secret/path/to/key.p12';

// Load the key in PKCS 12 format (you need to download this from the
// Google API Console when the service account was created.
$client = new Google_Client();