2014-12-05 78 views
2

當我爲某個賬戶添加聯繫信息時,我沒有看到谷歌通訊錄中顯示的工作地址。 我錯過了什麼設置?如何使用.Net和API獲取Google通訊錄中谷歌通訊錄中顯示的工作地址

我使用Directory API:https://developers.google.com/admin-sdk/directory/v1/reference/users/insert 我使用的NuGet包1.9.0.490

www.nuget.org/packages/Google.Apis/

我創建一個用戶,並設置自己的聯繫人信息。 但是,當我在谷歌聯繫人中查找帳戶時,我沒有看到地址信息。

List<UserAddress> newAddresses = new List<UserAddress>(); 
UserAddress newAddress = new UserAddress 
    { 
     Country = "Netherlands", 
     CountryCode = "NL", 
     Type = "work", 
     ExtendedAddress = "address extension", // just for demo 
     Locality = "amsterdam", 
     PoBox = "Postbus 1000", // just for demo 
     PostalCode = "1000 AA", 
     Primary = true, 
     Region = "Noord-Holland", // just for demo 
     StreetAddress = "Main street 1" 
    }; 
newAddresses.Add(newAddress); 
User newUser = new User 
    { 
     Name = "Demo User", 
     PrimaryEmail = "[email protected]", 
     Addresses = newAddresses, 
     ChangePasswordAtNextLogin = true, 
     Password = "*****", 
     IncludeInGlobalAddressList = true, 
     IpWhitelisted = true, 
     OrgUnitPath = @"/User/Demo/", 
     AgreedToTerms = true, 
     IsMailboxSetup = true 
    }; 

X509Certificate2 certificate = new X509Certificate2(@"\location\P12File.p12", "notasecret", X509KeyStorageFlags.Exportable); 
IEnumerable<string> scopes = new[] { DirectoryService.Scope.AdminDirectoryUser, DirectoryService.Scope.AdminDirectoryUserSecurity }; 
ServiceAccountCredential credential = new ServiceAccountCredential(
    new ServiceAccountCredential.Initializer("[email protected]") 
    { 
     Scopes = scopes, 
     User = "[email protected]" 
    }.FromCertificate(certificate)); 

// Create the service. 
var service = new DirectoryService(
    new BaseClientService.Initializer() 
    { 
     HttpClientInitializer = credential, 
     ApplicationName = "Admin directory Provisioning Sample", 
    }); 
service.Users.Insert(newUser).Execute(); 

當我通過代碼檢索用戶I可以看到,信息被存儲:

> +  Addresses {[ { 
>  "type": "work", 
>  "poBox": "Postbus 1000", 
>  "extendedAddress": "address extension", 
>  "streetAddress": "Main street 1", 
>  "locality": "amsterdam", 
>  "region": "Noord-Holland", 
>  "postalCode": "1000 AA", 
>  "country": "Netherlands", 
>  "primary": true, 
>  "countryCode": "NL" } ]} object {Newtonsoft.Json.Linq.JArray} 

我的聯繫人數據的圖像例如:

enter image description here

https://drive.google.com/file/d/0B6t050r4NXnDM2pUTjJoY0ZHMVU/view?usp=sharing

+0

如何運行你的代碼,你檢查目錄檔案後長時間?目錄中的聯繫信息每24小時更新一次(https://support.google.com/a/answer/1628009)。因此,如果自更新配置文件起至今還沒有至少一天,則預計它可能不會顯示。 – miketreacy 2014-12-06 15:53:06

+0

嗨,我知道約25小時的時間框架,所以在我發佈這個問題之前,我已經等了至少36個小時了。而且我檢查了這個mornimg,仍然沒有地址 – manrot 2014-12-07 09:09:25

回答

0

我遇到問題了我的地址也要顯示。在使用支持後,解決方案還需要更新「格式化」屬性,使用任何您想要顯示的地址。這似乎沒有記錄。

例子:

{ 
    "type":"work", 
    "formatted":"123 Nowhere Somewhereville MN 55555", 
    "streetAddress":"123 Nowhere", 
    "locality":"Somewhereville", 
    "region":"MN", 
    "postalCode":"55555" 
}