- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我是使用 Google API 的新手,但我有一个项目需要我访问他们的域以通过电子邮件查找用户的经理。在开始编写代码之前,我想设置所有内容,所以我遵循了 example file对于 PHP。我能够让它工作,但在 token 过期后刷新 token 时遇到一些问题,研究促使我使用 Service Account ,因为这是一个服务器 cron 脚本,我不想处理任何用户交互。
我创建了服务帐户,启用了 G Suite 全域委派,并添加了访问权限:https://www.googleapis.com/auth/admin.directory.user.readonly
我的脚本出现了 Google_Service_Exception
。
响应是:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "notFound",
"message": "Domain not found."
}
],
"code": 404,
"message": "Domain not found."
}
}
我假设这意味着它不知道帐户域,但我不知道如何解决这个问题。我假设如果这是一个权限问题,谷歌会告诉我。我尝试在线搜索但没有成功,因为我发现的问题是使用不同的方法,并且修复不是可以在服务帐户上完成的。我现在被困住了,所以我希望朝着正确的方向前进会让我走上正轨。
这是我正在使用的测试脚本:
<?php
require_once( __DIR__. '/vendor/autoload.php' );
define('CREDENTIALS_PATH', '/path/to/service_account.json');
define('SCOPES', implode(' ', array(
Google_Service_Directory::ADMIN_DIRECTORY_USER_READONLY)
));
date_default_timezone_set('America/New_York');
/**
* Returns an authorized API client.
* @return Google_Client the authorized client object
*/
function getClient() {
$client = new Google_Client();
$client->setApplicationName('TestingApp');
$client->setAuthConfig(CREDENTIALS_PATH);
$client->setScopes(SCOPES);
return $client;
}
// Get the API client and construct the service object.
$client = getClient();
$service = new Google_Service_Directory($client);
// Print the first 10 users in the domain.
$optParams = array(
'customer' => 'my_customer',
'maxResults' => 10,
'orderBy' => 'email',
);
$results = $service->users->listUsers($optParams);
if (count($results->getUsers()) == 0) {
print "No users found.\n";
} else {
print "Users:\n";
foreach ($results->getUsers() as $user) {
printf("%s (%s)\n", $user->getPrimaryEmail(),
$user->getName()->getFullName());
}
}
我的 service_account.json
包含(显然已清理)
{
"type": "service_account",
"project_id": "PROJECT_ID",
"private_key_id": "PRIVATE_KEY_ID",
"private_key": "PRIVATE_KEY",
"client_email": "SERVICE_ACCOUNT_EMAIL.iam.gserviceaccount.com",
"client_id": "CLIENT_ID",
"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_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/SERVICE_ACCOUNT_IDENTIFIER.iam.gserviceaccount.com"
}
感谢您对此提供的任何帮助。
最佳答案
好吧,这是一个非常容易忽略的步骤,但它是一个非常简单的修复。
这里的问题是帐户的域未被识别。我的印象是服务帐户已经附加到域,但事实并非如此。因此,修复只是添加到客户端以将其设置为域中的用户的一行代码(对于我的情况)。
我的解决方法是添加:
$client->setSubject('account@domain.com');
到我的 getClient
方法。
所以现在该方法看起来像:
/**
* Returns an authorized API client.
* @return Google_Client the authorized client object
*/
function getClient() {
$client = new Google_Client();
$client->setApplicationName('TestingApp');
$client->setAuthConfig(CREDENTIALS_PATH);
$client->setScopes(SCOPES);
$client->setSubject('account@domain.com');
return $client;
}
我看到这个提到 in the API但它声明它是可选的。希望这也会对其他人有所帮助。
关于php - 谷歌 API : 404 Domain not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39990327/
我遇到了搜索引擎优化问题,用户可以通过指定任何子域访问我的站点。这会导致 SEO 出现重复页面问题。 例如,如果用户错误输入“www”然后在论坛上发布了一个链接,则谷歌正在抓取“wwww.domain
这个问题在这里已经有了答案: 关闭10 年前。 Possible Duplicates: Can I change all my links to just //? Network-Path Ref
我正在玩 lighttpd在小型虚拟专用服务器上。我两个域指向服务器。我在 Ubuntu 8.10 上使用最新版本的 lighttpd 和 mod_evhost。 我正在尝试设置一个规则,这样如果任何
我正在开发一个由 domain.ext 提供的网络应用程序。此 Web 应用程序使用基于 cookie 的 session ,并为用户提供在子域上托管包含自定义 JavaScript 的网页的能力,例
我想重定向: 情况一、example.com到subdomain.example.com 情况2.www.example.com到subdomain.example.com 我已将这两段代码放入我的
我遇到了“领域对象”这个术语,并在 Google 上找到了几个定义,但我只是想验证我的理解是否正确。 这是否只是表示业务规则的任何类 - 因为“域”一词通常表示特定于某些本地问题集的规则,例如如何计算
将我们的应用程序静态内容托管在一个完全不同的域上而不是像其他域一样托管在我们主域的子域上有什么好处吗?例如微软使用 i.microsoft.com,谷歌使用 gstatic.com,雅虎使用 yimg
Orbited的客户端JS组件( cometd 服务器),要求如果服务器运行在与 JS 本身不同的域或端口上,则必须执行 document.domain = document.domain; 在加载任
我通读了另一篇文章,但似乎没有人回答我一直遇到的问题。是否可以使用通配符域的通配符子域(即使它仅用于子域而不是子子域),例如:foo.example.local。 我已经有 example.local
我在 Google Domains 上有一个域名,我想指向我在家里的 raspberry pi 服务器上运行的网站。我的公共(public) IP 地址是动态的,当 IP 更新时,我无法弄清楚如何保持
我有这个经典的 DDD 问题;我有一个做一些事情的域服务“DetectPriority”。 PM 要求我创建 2 个不同的服务;一个 INTERNAL(包含完整的业务规则并涉及许多其他领域模型)和另一
An interesting thread我刚才输入这个问题时就出现了。但我认为它没有回答我的问题。 我一直在使用 .NET MVC3 进行大量工作,因此需要一个贫乏的模型。 View 模型和编辑模型
我正在通过docker-compose运行最新版本的Artifactory OSS(如here和here所述)。我的docker-compose文件看起来像这样: version: '2' servi
我正在阅读 MDC entry for nsICookieManager2.add它讨论了域和非域 cookie。这两种类型的 cookie 有什么区别? 最佳答案 来自 RFC2109: Host
这是我的问题:http://regexr.com?2temn 我相信对于你们中的一些正则表达式大师来说这很简单。 干杯! 最佳答案 这也有效: (?<=\.|)\w+\.\w+$ 仅使用 PHP 进行
这应该很简单,但我无法理解。有许多好的和坏的正则表达式方法来匹配 URL,有或没有协议(protocol),有或没有 www。我遇到的问题是这个(在 javascript 中):如果我使用正则表达式来
我有一个网站 http://mywebsite.tld ,我想将 www.mywebsite.tld 重定向到 http://mywesite.tld (所以 www=>非 www) (防止重复内容)
TL;DR 我应该从 www.domain.tld 重定向到 domain.tld 还是相反? 我正在运行一个处理多个域的 CMS。到目前为止,CMS 负责将 www.domain.tld 重定向到
我目前有以下代码: string user = @"DOMAIN\USER"; string[] parts = user.Split(new string[] { "\\" }, StringSpl
使用 Go 和 AWS-SDK 我正在尝试查询 AWS 控制台中 Route53 -> Hosted Zones 下列出的 route53 CNAME 和 A 记录。我可以使用以下代码进行查询,但它需
我是一名优秀的程序员,十分优秀!