2010-03-26 27 views
1

我想使用「Google.GData.Extensions.Apps」在Google聯繫人中添加「暱稱」。如何在聯繫人條目中添加暱稱?

我能夠創建暱稱爲:

NicknameElement obj_nickname =新NicknameElement(); obj_nickname.Name =「Jenifer」;

但如何將我添加到聯繫人條目?

回答

1

聯繫人API支持使用gContact:nickname元素的暱稱。這個元素在聯繫人API的3.0版本中是新的,因此位於gContact命名空間中。例如:

<atom:entry xmlns:atom='http://www.w3.org/2005/Atom' 
    xmlns:gd='http://schemas.google.com/g/2005'> 
    <atom:category scheme='http://schemas.google.com/g/2005#kind' 
     term='http://schemas.google.com/contact/2008#contact' /> 
    <gd:name> 
    <gd:givenName>Victor</gd:givenName> 
    <gd:familyName>Fryzel</gd:familyName> 
    <gd:fullName>Vic Fryzel</gd:fullName> 
    </gd:name> 

    <!-- ... --> 

    <gContact:nickname>Vic</gContact:nickname> 
</atom:entry> 

幸運的是,.NET客戶端庫已經更新了一個getter和setter此參數,雖然方法都在.NET Developer's Guide無證。但是,您可以在the source code中找到它們。它們的源代碼位於:

因此,您可以使用以下代碼來設置聯繫人的暱稱。

Contact newContact = new Contact(); 
newContact.Title.Text = "Victor Fryzel"; 
newContact.Nickname = new Nickname("Vic"); 
// ... 
// This example assumes the ContactRequest object (cr) is already set up. 
Contact createdContact = cr.Insert(newContact); 

欲瞭解更多信息,請參閱.NET Developer's Guide。祝你好運!

0

爲了進一步幫助別人,

使用最新的.NET API,我需要設置暱稱稍有不同,因爲我無法找到暱稱對象。我會保持它類似於維克的答案,以擴大而不是取代它。這種方法已經過測試,適用於我。對不起維克,如果我錯過了你的解決方案,我還不能添加評論。

Contact newContact = new Contact(); 
newContact.Title.Text = "Victor Fryzel"; 
newContact.ContactEntry.Nickname = "nicknameString"; 
// ... 
// This example assumes the ContactRequest object (cr) is already set up. 
Contact createdContact = cr.Insert(newContact); 

根據文檔包含命名空間。

using Google.Contacts; 
using Google.GData.Contacts; 
using Google.GData.Client; 
using Google.GData.Extensions; 
相關問題