0

我正在通过 Google .net 客户端库为组织单位调用获取、更新和删除 API,但得到 404。我使用了 Fiddler,发现请求 URL 格式不正确。我在 URL 中看到 {/orgUnitPath*} 字符串而不是我的组织单位路径,并且客户 ID 被替换为实际的客户 ID,我在 Fiddler 中使用实际的组织单位路径提出了该请求,它工作正常。

我的组织单位路径是 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
4

3 回答 3

1

首先,您使用的是旧版本的库。请使用 NuGet 执行以下操作:

然后尝试执行以下操作:

OrgUnit orgUnit = service.Orgunits.Get(CustomerId).Execute();

于 2013-09-23T14:47:47.367 回答
1

我有同样的问题。但问题出在 orgunitpath 和我的可重复参数上。orgunitpath 的格式为“/ABC/IT”。一旦我将其更改为“ABC/IT”,它对我来说效果很好。我初始化Repeatable的方式也有一点不同。

我直接使用字符串列表代替可重复参数。

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();"
于 2015-11-11T07:10:21.660 回答
0

At last I used REST operations to achieve it, let me know if anyone come across a solution. Following is the code:

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;
    }
于 2013-09-28T12:30:36.610 回答