Microsoft.PowerShell.GData.Dgc.GoogleAppService.GetCustomerId C# (CSharp) Method

GetCustomerId() public method

public GetCustomerId ( Google.GData.Apps.AppsService CustIdService ) : string
CustIdService Google.GData.Apps.AppsService
return string
            public string GetCustomerId(AppsService CustIdService)
            {
                var Token = CustIdService.Groups.QueryClientLoginToken();
                var uri = new Uri("https://apps-apis.google.com/a/feeds/customer/2.0/customerId");

                WebRequest WebRequest = WebRequest.Create(uri);
                WebRequest.Method = "GET";
                WebRequest.ContentType = "application/atom+xml; charset=UTF-8";
                WebRequest.Headers.Add("Authorization: GoogleLogin auth=" + Token);

                WebResponse WebResponse = WebRequest.GetResponse();

                if (WebResponse == null)
                {
                    throw new Exception("WebResponse is null");
                }
                StreamReader SR = new StreamReader(WebResponse.GetResponseStream());

                var _Result = SR.ReadToEnd().Trim();
                var Xml = new ParseXML(_Result);

                foreach (var x in Xml.ListFormat)
                {
                    if (x.Name == "customerId")
                    {
                        CustomerId = x.Value;
                    }

                }

                return CustomerId;
            }

Usage Example

Example #1
0
            public string RetrieveOU(AppsService UserService, string OuPath)
            {
                var Token = UserService.Groups.QueryClientLoginToken();
                var OUService = new Dgc.GoogleAppService();
                var CustId = OUService.GetCustomerId(UserService);

                var uri = new Uri("https://apps-apis.google.com/a/feeds/orgunit/2.0/" + CustId + "/"+OuPath);

                WebRequest WebRequest = WebRequest.Create(uri);
                WebRequest.Method = "GET";
                WebRequest.ContentType = "application/atom+xml; charset=UTF-8";
                WebRequest.Headers.Add("Authorization: GoogleLogin auth=" + Token);

                WebResponse WebResponse = WebRequest.GetResponse();

                if (WebResponse == null)
                {
                    throw new Exception("WebResponse is null");
                }
                StreamReader SR = new StreamReader(WebResponse.GetResponseStream());

                var _Result = SR.ReadToEnd().Trim();

                return _Result;
            }