下面的脚本可以帮助我得到我的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
?我也需要让每一个接触的标签(或组)。请帮忙。
我建议你通过了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()
。
参考
好。 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);
}