Пример #1
0
        public string GetUserMailIdv2(string accessToken)
        {
            try
            {
                Dictionary <string, string> requestParams = new Dictionary <string, string>();
                HttpClient http = new HttpClient();

                requestParams.Add("client_id", oAuthParams.ClientId);
                requestParams.Add("client_secret", oAuthParams.ClientSecret);
                requestParams.Add("redirect_uri", oAuthParams.RedirectURL);

                JObject JsonObject = new JObject();
                JsonObject.Add(new JProperty("client_id", oAuthParams.ClientId));
                JsonObject.Add(new JProperty("client_secret", oAuthParams.ClientSecret));
                JsonObject.Add(new JProperty("redirect_uri", oAuthParams.RedirectURL));

                StringContent oString = new StringContent(JsonObject.ToString());
                http.DefaultRequestHeaders.Add("authorization", ZohoOAuthConstants.AuthHeaderPrefix + accessToken);

                HttpResponseMessage response = http.PostAsync(ZohoOAuth.GetUserInfoURL(), oString).Result;
                string res = response.Content.ReadAsStringAsync().Result;

                return(res);
            }
            catch (Exception) { throw; }
        }
Пример #2
0
        //TODO: the method throws three exceptions and check for null exception on access_token.
        public string GetUserMailId(string accessToken)
        {
            try
            {
                ZohoHTTPConnector conn = new ZohoHTTPConnector()
                {
                    Url = ZohoOAuth.GetUserInfoURL()
                };
                //conn.AddHeader("Authorization", ZohoOAuthConstants.AuthHeaderPrefix + accessToken);
                conn.AddHeader("Authorization", ZohoOAuthConstants.Bearer + accessToken);
                string  response     = conn.Get();
                JObject responseJSON = JObject.Parse(response);

                if (response == null)
                {
                    return(null);
                }
                else
                {
                    return(responseJSON["Email"].ToString());
                }
            }
            catch (WebException) { throw; }
        }