【发布时间】:2016-08-04 10:52:52
【问题描述】:
我正在使用 Google Apps for Work,并且有一个服务帐户来访问 PHP 中的 Drive API。
我现在的代码是:
$client = new Google_Client();
$client->setApplicationName('MyApp');
$key = file_get_contents("/path/to/secure/key");
$cred = new Google_Auth_AssertionCredentials(
"serviceaccount@myapp.iam.gserviceaccount.com",
array('https://www.googleapis.com/auth/drive', 'https://spreadsheets.google.com/feeds'),
$key, 'keysecretgoeshere', 'http://oauth.net/grant_type/jwt/1.0/bearer', "email@domain.com"
);
$client->setAssertionCredentials($cred);
当我将它上传到我的外部托管的 Apache 服务器时,这非常有效。奇怪的是,我还有一个本地服务器,使用 EasyPHP 在本地测试,一访问页面,就出现“无法访问此站点。连接已重置”错误。
关于为什么它不能从 localhost 工作,我有什么遗漏吗? 可能是未安装 PHP 扩展或一些 cURL/openSSL 问题?
【问题讨论】:
标签: php google-app-engine google-api google-apps service-accounts