3
我正在使用此页面的代码http://code.google.com/apis/contacts/docs/1.0/developers_guide_js.html来获取gmail联系人列表。实际上,它工作正常,但我得到的名称,地址等像一个简单的字符串的数据,为“\ n”作为分隔符,例如:如何使用javascript Google联系人API以更详细的格式导入Gmail联系人的数据?
<script type="text/javascript">
var contactsService;
var scope = 'https://www.google.com/m8/feeds';
function setupContactsService() {
//contactsService = new google.gdata.contacts.ContactsService('exampleCo-exampleApp-1.0');
contactsService = new google.gdata.contacts.ContactsService('GoogleInc-jsguide-1.0');
}
function getMyContacts() {
var contactsFeedUri = 'https://www.google.com/m8/feeds/contacts/default/full'; //?max-results=9999&alt=json&v=3.0
var query = new google.gdata.contacts.ContactQuery(contactsFeedUri);
setupContactsService();
contactsService.getContactFeed(query, handleContactsFeed, handleError);
}
var handleContactsFeed = function(result) {
var entries = result.feed.entry;
for (var i = 0; i < entries.length; i++) {
var entry = entries[i];
var addrs = entry.getPostalAddresses();
var name = entry.getTitle();
// logging
console.log(addrs[0]);
console.log(name);
}
}
function handleError(e) {
alert(e.cause ? e.cause.statusText : e.message);
}
</script>
它给了我一个对象,其中的名称和地址的值是简单字符串。
我能以某种方式得到类似关联数组格式的数据,其中地址将包含街道,邮编,城市,国家的单独值;和名头名的独立价值,姓氏等
像:提前
{
"type": "address",
"value":
{
"street": "Starret 1234",
"city": "City name",
"stateOrProvince": "ca",
"postalCode": "73000",
"country": "USA"
}
},
{
"type": "name",
"value":
{
"firstName": "Allen",
"lastName" : "Iverson",
.....
}
}
谢谢!
这个例子unfortuanely缺乏大量Ø f实现位。 – NiKo