2013-09-23 47 views
0

我打算通過Google .net客戶端庫調用組織單元的獲取,更新和刪除API,但獲得404。我使用Fiddler並看到請求URL格式錯誤。而不是我的組織單位路徑,我在URL中看到{/ orgUnitPath *}字符串,並且客戶ID由實際的客戶ID替換,我用Fiddler中的實際組織單元路徑進行了該請求,並且工作正常。Google目錄api組織單元錯誤404

我的組織單元的路徑是ABC/IT,我以爲有一些問題初始化字符串重複,因爲我的插件和API的名單做工精細:

Repeatable<string> rep = new Repeatable<string>(new List<string>{orgUnitPath}); 

OrgunitsResource.GetRequest gr = service.Orgunits.Get(GetGoogleUser(ConfigManager.AdminIdentity, accessToken).CustomerId, rep); 

OrgUnit orgUnit = gr.Fetch(); 

我在這裏幹什麼什麼了嗎?

我更新客戶端庫後的新代碼:

public OrgUnit GetGoogleOrganizationUnit(string orgUnitPath, string accessToken) 
     { 
      AccessToken = accessToken; 
      var service = new DirectoryService(GetGoogleServiceClient()); 

      Repeatable<string> rep = new Repeatable<string>(new List<string> { orgUnitPath }); 

      OrgunitsResource.GetRequest gr = service.Orgunits.Get(GetGoogleUser(ConfigManager.AdminIdentity, accessToken).CustomerId, rep); 

      OrgUnit orgUnit = gr.Execute(); 

      return orgUnit; 
     } 

以下是堆棧跟蹤:

所有的
[JsonReaderException: Error parsing NaN value. Path '', line 0, position 0.] 
    Newtonsoft.Json.JsonTextReader.ParseNumberNaN() +97 
    Newtonsoft.Json.JsonTextReader.ParseValue() +400 
    Newtonsoft.Json.JsonTextReader.ReadInternal() +35 
    Newtonsoft.Json.JsonTextReader.Read() +20 
    Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter) +74 
    Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) +442 
    Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) +687 
    Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) +111 
    Newtonsoft.Json.JsonConvert.DeserializeObject(String value, JsonSerializerSettings settings) +66 
    Newtonsoft.Json.JsonConvert.DeserializeObject(String value) +42 
    Google.Apis.Json.NewtonsoftJsonSerializer.Deserialize(String input) in c:\code.google.com\google-api-dotnet-client\default_3\Tools\Google.Apis.Release\bin\Debug\output\default\Src\GoogleApis\Apis\Json\NewtonsoftJsonSerializer.cs:72 
    Google.Apis.Services.<DeserializeError>d__9.MoveNext() in c:\code.google.com\google-api-dotnet-client\default_3\Tools\Google.Apis.Release\bin\Debug\output\default\Src\GoogleApis\Apis\Services\BaseClientService.cs:357 

[GoogleApiException: An Error occurred, but the error response could not be deserialized] 
    BLL.GoogleAPIManagerBLL.GetGoogleOrganizationUnit(String orgUnitPath, String accessToken) in c:\Projects\FGPortal\BLL\GoogleAPIManagerBLL.cs:504 
    Application.ManageOrgUnits.gvorgunits_RowCommand(Object sender, GridViewCommandEventArgs e) in c:\Projects\FGPortal\Application\ManageOrgUnits.aspx.cs:29 
    System.Web.UI.WebControls.GridView.OnRowCommand(GridViewCommandEventArgs e) +111 
    System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +73 
    System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e) +89 
    System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37 
    System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +88 
    System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37 
    System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +121 
    System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +156 
    System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +9642898 
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724 

回答

1

首先,你使用的是舊版本的庫。請不要在使用的NuGet如下:

,然後嘗試做到以下幾點:

單位部門ORGUNIT = service.Orgunits.Get(客戶ID).Execute();

+0

我得到的錯誤,當我嘗試安裝包:您正在嘗試這個軟件包安裝到靶向」 .NETFramework,版本= 4.0' 版的一個項目,但 不包含任何程序集的引用包與該框架兼容 – AdnanQ

+0

我更新了我的nuget管理器並獲取了包 – AdnanQ

+0

當我安裝了包時,它開始爲我提供了.net framework 4.0的衝突,即使在web.config中有程序集綁定重定向。 – AdnanQ

0

最後我用REST操作實現它,讓我知道是否有人遇到了解決方案。以下是代碼:

public OrgUnit GetGoogleOrganizationUnit(string orgUnitPath, string accessToken) 
     { 
      AccessToken = accessToken; 
      var service = new DirectoryService(GetGoogleServiceClient()); 

     HttpWebRequest request = (HttpWebRequest)WebRequest.Create(String.Format("https://www.googleapis.com/admin/directory/v1/customer/{0}/orgunits/{1}", GetGoogleUser(ConfigManager.AdminIdentity, accessToken).CustomerId, HttpUtility.UrlEncode(orgUnitPath))); 
     request.Method = "GET"; 
     request.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + accessToken); 

     HttpWebResponse response = (HttpWebResponse)request.GetResponse(); 
     StreamReader sr = new StreamReader(response.GetResponseStream()); 

     var jLinq = JObject.Parse(sr.ReadToEnd()); 

     OrgUnit orgUnit = new OrgUnit(); 

     orgUnit.Kind = jLinq["kind"].ToString(); 
     orgUnit.ETag = jLinq["etag"].ToString(); 
     orgUnit.Name = jLinq["name"].ToString(); 
     orgUnit.Description = jLinq["description"].ToString(); 
     orgUnit.OrgUnitPath = jLinq["orgUnitPath"].ToString(); 
     orgUnit.ParentOrgUnitPath = jLinq["parentOrgUnitPath"].ToString(); 
     orgUnit.BlockInheritance = Convert.ToBoolean(jLinq["blockInheritance"]); 

     return orgUnit; 
    } 
0

我有同樣的問題。但問題出在orgunitpath和我的可重複參數上。 orgunitpath格式爲「/ ABC/IT」。一旦我將它改爲「ABC/IT」,它對我來說工作得很好。在我初始化可重複模式的方式上也有一點小差異。

我直接在可重複參數的地方使用了一個字符串列表。

List<string> list = new List<string>(); 

list.Add("ABC/IT"); 

OrgunitsResource.GetRequest orgUnitRequest = googleAppsOAuthService.Orgunits.Get(superAdminImmutableId, list); 

Google.Apis.Admin.Directory.directory_v1.Data.OrgUnit orgUnit = orgUnitRequest.Execute();"