如何从contacts.google.com提取联系人的URL

问题描述 投票:1回答:2

下面的脚本可以帮助我得到我的https://contacts.google.com每个联系人的姓名和地址。

function extract_contacts() {
  var s = '';
  var contacts = ContactsApp.getContacts();
    for (var i in contacts) {
      var name = contacts[i].getFullName();
      var id = contacts[i].getId();
      var url = contacts[i].getUrls();
      s+=name+" ·· "+url+"\r";
    }
  Logger.log(s);
}

问题是,getUrls显示UrlField结果,而不是保存在该领域的实际的URL,这样的事情:

friend ·· UrlField
another_friend ·· UrlField,UrlField

我应该用什么来代替getUrls?我也需要让每一个接触的标签(或组)。请帮忙。

google-apps-script google-contacts
2个回答
2
投票

我建议你通过了URLField阵列分析,抓住地址为这样:

function extract_contacts() {
  var s = '';
  var contacts = ContactsApp.getContacts();
    for (var i in contacts) {
      var adresses ="";
      var name = contacts[i].getFullName();
      var id = contacts[i].getId();
      var urlFields = contacts[i].getUrls();
      for (var j = 0; j < urlFields.length; j++)
        adresses += urlFields[j].getAddress() + " ";
      s+=name+" ·· "+ adresses +"\r";
    }
  Logger.log(s);
}

团体同样的事情用getContactGroups()和分析通过阵列,然后使用getName()or getId()

参考

URLField Class

contactGroup Class


1
投票

好。 jsmith的帮助和增加了一些替代品和字母排序后,这里是它。最后,脚本输出结果为谷歌网站页面:

function extractContacts() {
  var s = '';
  var contacts = ContactsApp.getContacts();
    for (var i in contacts) {

      var adresses = "";
      var groups = "";
      var name = contacts[i].getFullName();
      var id = contacts[i].getId();

      var urlFields = contacts[i].getUrls();
      for (var j = 0; j < urlFields.length; j++)
        adresses += '* <a href="'+urlFields[j].getAddress()+'" target="_blank">'+urlFields[j].getAddress()+'</a><br>';

      var group = contacts[i].getContactGroups();
      for (var k = 0; k < group.length; k++)
        groups += group[k].getName() + " · ";

      if(adresses==''){var groups=''; var name='';}
      s+='<h3>'+groups+' · '+name+'</h3><blockquote>'+adresses+"</blockquote>#####";
    }

var s = s.replace(/System Group: My Contacts · /g,"");
var s = s.replace(/,/g,"&&&&&");

var aorder = s.split("#####").sort(function (a, b) {
  return a.localeCompare(b);
});
var s = aorder.toString();
var s = s.replace(/,/g,'<br>');
var s = s.replace(/&&&&&/g,',');
var s = s.replace(/·  ·/g,':');
var s = s.replace(/<br><h3> · <\/h3>/g,'');

var site = SitesApp.getSite('site','clicamiento');
var home = site.getChildByName('/home');
home.setHtmlContent('<h1>CLICAMIENTO</h1>'+s);

}
© www.soinside.com 2019 - 2024. All rights reserved.