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