2014-10-16 71 views
0

好吧,經過本網站和其他人的帖子很多幫助後,我終於有了我的.net應用程序連接並驗證到我的谷歌應用程序實例!萬歲!我可以使用我已委派訪問的服務帳戶搜索並獲取用戶詳細信息,使我的心情愉悅。谷歌目錄API和重置用戶密碼通過.net

這就是說,我似乎無法更新用戶的密碼。我沒有收到任何錯誤,沒有迴應,也沒有收到任何迴應 - 它不起作用。

這就是我到目前爲止,就像我說的,我得到的用戶細節很好,只是不能更改密碼!

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Security.Cryptography.X509Certificates; 

using Google.Apis.Auth.OAuth2; 
using Google.Apis.Services; 
using Google.Apis.Admin.Directory.directory_v1; 
using Google.Apis.Admin.Directory.directory_v1.Data; 
using Google.Apis.Admin.Directory; 


String serviceAccountEmail = "[email protected]"; 
var certificate = new X509Certificate2(@"c:\path\to\my\p12key.p12", "mysecret", X509KeyStorageFlags.Exportable); 


ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(serviceAccountEmail) 
{ 
    User="[email protected]", 

    Scopes = new[] { DirectoryService.Scope.AdminDirectoryUser } 
}.FromCertificate(certificate)); 



var dirservice = new DirectoryService(new BaseClientService.Initializer() 
{ 
    HttpClientInitializer = credential, 
    ApplicationName = "MyProjectName", 
}); 

User user = dirservice.Users.Get("[email protected]").Execute(); 
Console.WriteLine(" email: " + user.PrimaryEmail); 
Console.WriteLine(" last login: " + user.LastLoginTime); 

user.Password = "newpassword"; 
dirservice.Users.Update(user, "[email protected]"); 

最後兩行是我預料會改變用戶密碼的 - 但事實並非如此。

任何幫助在這裏將不勝感激!非常感謝!

回答