【问题标题】:Is there a way to add a second custom field in google people api when creating a person?创建人时,有没有办法在 google people api 中添加第二个自定义字段?
【发布时间】:2022-01-17 13:27:45
【问题描述】:

我正在以特定方式从 csv 文件导入 google 联系人,在文件中我有 2 个自定义字段需要在导入时添加到每个联系人。我已经添加了第一个自定义字段,但不知道如何以编程方式添加第二个。似乎有可能,因为您可以从联系页面添加第二个自定义字段。下面是为联系人添加一个自定义字段的代码:

$opened_file=fopen("export_test.csv", "r");
while(($data = fgetcsv($opened_file, 1000,",")) !== FALSE)
{
  $contacts[] = $data;
}


$person = new Google_Service_PeopleService_Person();
$custom_field = new Google_Service_PeopleService_UserDefined();

for($i = 1; $i < count($contacts); $i++)
{
  $custom_field->setKey($contacts[$i][50]);
  $custom_field->setValue($contacts[$i][51]);

  $person->setUserDefined($custom_field);
}

我尝试创建一个新的用户定义对象,设置键和值并将其附加到人,但这只会覆盖第一个自定义字段。我也查过这个问题,但一无所获。是否可以通过编程方式添加第二个自定义字段?

【问题讨论】:

    标签: php google-api-php-client google-people-api


    【解决方案1】:

    UserDefined 是文档https://developers.google.com/people/api/rest/v1/people#resource:-person 中的列表

    我不确定 PHP 语法,但基于 https://github.com/googleapis/google-api-php-client 中的示例,尝试做

    $custom_field_array = array();
    
    ...
    
    $person->setUserDefined($custom_field_array);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-30
      • 2018-07-23
      • 1970-01-01
      相关资源
      最近更新 更多