Example #1
0
        public string Fetch(string code, string node)
        {
            string jsonStr = string.Empty;

            try {
                string postData = "code=" + code + "&redirect_uri=" + HttpContext.Current.Server.UrlEncode(this.RedirectUri) + "&client_id=" + ClientId + "&client_secret=" + ClientSecret + "&grant_type=authorization_code";
                Web_Request             = WebRequest.Create(googleApiUrl + "token?" + postData);
                Web_Request.Method      = "POST";
                Web_Request.ContentType = "application/x-www-form-urlencoded";

                byte[] byteArray = Encoding.UTF8.GetBytes(postData);
                Web_Request.ContentLength = byteArray.Length;

                using (Stream dataStream = Web_Request.GetRequestStream()) {
                    dataStream.Write(byteArray, 0, byteArray.Length);
                }

                GoogleToken token = new GoogleToken();

                using (Web_Response = Web_Request.GetResponse()) {
                    using (Stream stream = Web_Response.GetResponseStream()) {
                        StreamReader reader = new StreamReader(stream);
                        token = new JavaScriptSerializer().Deserialize <GoogleToken>(reader.ReadToEnd());
                    }
                }

                jsonStr = GetUserInfo(token);
            }
            catch { }

            return(jsonStr);
        }
Example #2
0
        private string GetUserInfo(GoogleToken token)
        {
            string jsonStr = string.Empty;

            if (!string.IsNullOrEmpty(token.access_token))
            {
                Web_Request = WebRequest.Create("https://www.googleapis.com/plus/v1/people/me?access_token=" + token.access_token);

                using (Web_Response = Web_Request.GetResponse()) {
                    using (Stream stream = Web_Response.GetResponseStream()) {
                        StreamReader reader = new StreamReader(stream);
                        jsonStr = reader.ReadToEnd();
                    }
                }
            }

            return(jsonStr);
        }
Example #3
0
        private void DeletePermissions(string node)
        {
            if (!string.IsNullOrEmpty(AccessToken))
            {
                Web_Request        = WebRequest.Create(graphApiUrl + node + "/permissions?access_token=" + AccessToken);
                Web_Request.Method = "DELETE";

                using (Web_Response = Web_Request.GetResponse()) {
                    using (Stream stream = Web_Response.GetResponseStream()) {
                        StreamReader        reader = new StreamReader(stream);
                        FaceBookPermissions faceBookPermisssions = new JavaScriptSerializer().Deserialize <FaceBookPermissions>(reader.ReadToEnd());

                        if (faceBookPermisssions != null && faceBookPermisssions.success.ToLower() == "true")
                        {
                            AccessToken = string.Empty;
                        }
                    }
                }
            }
        }
Example #4
0
        private string GetUserInfo(string node)
        {
            string jsonStr = string.Empty;

            if (!string.IsNullOrEmpty(AccessToken))
            {
                try {
                    Web_Request        = WebRequest.Create(graphApiUrl + node + "?access_token=" + AccessToken);
                    Web_Request.Method = "GET";

                    using (Web_Response = Web_Request.GetResponse()) {
                        using (Stream stream = Web_Response.GetResponseStream()) {
                            StreamReader reader = new StreamReader(stream);
                            jsonStr = reader.ReadToEnd();
                        }
                    }

                    DeletePermissions(node);
                }
                catch { }
            }

            return(jsonStr);
        }
Example #5
0
        public string Fetch(string code, string node)
        {
            try {
                Web_Request        = WebRequest.Create("https://graph.facebook.com/oauth/access_token?client_id=" + API_Key + "&redirect_uri=" + this.Redirect_Url + "&client_secret=" + API_Secret + "&code=" + code);
                Web_Request.Method = "GET";

                using (Web_Response = Web_Request.GetResponse()) {
                    using (Stream stream = Web_Response.GetResponseStream()) {
                        StreamReader reader          = new StreamReader(stream);
                        string       tempAccessToken = reader.ReadToEnd();
                        try {
                            FacebookAccessTokenRequest facebookAccess = new JavaScriptSerializer().Deserialize <FacebookAccessTokenRequest>(tempAccessToken);
                            AccessToken = facebookAccess.access_token;
                        }
                        catch {
                            AccessToken = tempAccessToken;
                        }
                    }
                }
            }
            catch { }

            return(GetUserInfo(node));
        }