google-apps-script - 使用 Google Script 和 People API 指定来源会覆盖同步令牌
问题描述
我在https://developers.google.com/people/api/rest/v1/people.connections/list使用 Google 的“Try It”运行此代码。
<script src="https://apis.google.com/js/api.js"></script>
<script>
/**
* Sample JavaScript code for people.people.connections.list
* See instructions for running APIs Explorer code samples locally:
* https://developers.google.com/explorer-help/guides/code_samples#javascript
*/
function authenticate() {
return gapi.auth2.getAuthInstance()
.signIn({scope: "https://www.googleapis.com/auth/contacts https://www.googleapis.com/auth/contacts.readonly"})
.then(function() { console.log("Sign-in successful"); },
function(err) { console.error("Error signing in", err); });
}
function loadClient() {
return gapi.client.load("https://people.googleapis.com/$discovery/rest?version=v1")
.then(function() { console.log("GAPI client loaded for API"); },
function(err) { console.error("Error loading GAPI client for API", err); });
}
// Make sure the client is loaded and sign-in is complete before calling this method.
function execute() {
return gapi.client.people.people.connections.list({
"resourceName": "people/me",
"personFields": "names",
"sources": [
"READ_SOURCE_TYPE_CONTACT"
],
"syncToken": "MisAPB3nNAAAABIIsK7pgqKn8gIQsK7pgqKn8gI4IFedl0ChD-QAdeetUtBPOgw2ODIzOTA3NzkxNzA="
})
.then(function(response) {
// Handle the results here (response.result has the parsed body).
console.log("Response", response);
},
function(err) { console.error("Execute error", err); });
}
gapi.load("client:auth2", function() {
gapi.auth2.init({client_id: "YOUR_CLIENT_ID"});
});
</script>
<button onclick="authenticate().then(loadClient)">authorize and load</button>
<button onclick="execute()">execute</button>
当我排除
"sources": ["READ_SOURCE_TYPE_CONTACT"]
从“执行”函数中,代码仅返回自上次设置同步令牌以来更改的联系人(我想要的结果)。但是,当我包含该行时,我的所有联系人都会返回。任何人都知道为什么会发生这种情况以及如何避免它(除了删除该行 - 我需要排除 DOMAIN 和 PROFILE 源)?谢谢!
解决方案
根据文档:
-
来源[]
选修的。要返回的源类型的掩码。如果未设置,则默认为 READ_SOURCE_TYPE_CONTACT 和 READ_SOURCE_TYPE_PROFILE。
When the pageToken or syncToken is specified, all other request parameters must match the first call.
.
换句话说,一般来说,无论您设置"sources": ["READ_SOURCE_TYPE_CONTACT"]
与否,它都不应该有所不同 - 因为sources
自动默认为READ_SOURCE_TYPE_CONTACT
.
API 未正确返回唯一新联系人的最可能原因是您通过排除该行更改了请求"sources": ["READ_SOURCE_TYPE_CONTACT"]
(也许您还更改了其他内容?)。
推荐阅读
- r - R套索逻辑回归glmnet - 如何创建分层样本
- c++ - Crypto++ HexEncoder 无法始终如一地工作
- android-jetpack-compose - Jetpack Compose:无法解析堆栈
- sql - SQL中的动态减法
- java - 使用 jpa findall java 从表中仅获取一些属性
- c++ - NtCreateUserProcess 之后的 NtResumeThread
- php - Laravel 相当于 sql 日期时间转换
- javascript - 在Vuejs中离开页面时如何在url路径中保存页码
- shell - SingleColumnValueFilter 未正确过滤表
- terraform - Terraform 模块之间的可共享“计数”元参数?