public void Post(UserSocialConnection ConnectionData, string Update)
        {
            try
            {
                string apiCallUrl = String.Format("https://graph.facebook.com/me/feed"); // Format the call string
                HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(apiCallUrl);
                wr.Method = "POST";
                wr.ContentType = "application/x-www-form-urlencoded";

                string data = "access_token=" + ConnectionData.Token + "&message=" + HttpUtility.UrlEncode(Update);
                wr.ContentLength = data.Length;
                StreamWriter sw = new StreamWriter(wr.GetRequestStream());
                sw.Write(data);
                sw.Close();

                StreamReader sr = new StreamReader(wr.GetResponse().GetResponseStream());
                string jsonResponse = sr.ReadToEnd();

                sr.Close();

                sw.Dispose();
                sr.Dispose();

                if (jsonResponse.Contains("\"error_code\"")) // Proces the response for errors - a simple throw is used to convert the text error in to an exception
                    throw new Exception(String.Format("Error calling facebook API!\nJSON: {0} \nAPI CALL: {1}", jsonResponse, apiCallUrl));
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception occurred in FacebookSocialConnector.Post processing User ID #" + ConnectionData.UserId + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace);
            }
        }
Exemplo n.º 2
0
        public void Post(UserSocialConnection ConnectionData, string Update)
        {
            try
            {
                string         apiCallUrl = String.Format("https://graph.facebook.com/me/feed"); // Format the call string
                HttpWebRequest wr         = (HttpWebRequest)WebRequest.Create(apiCallUrl);
                wr.Method      = "POST";
                wr.ContentType = "application/x-www-form-urlencoded";

                string data = "access_token=" + ConnectionData.Token + "&message=" + HttpUtility.UrlEncode(Update);
                wr.ContentLength = data.Length;
                StreamWriter sw = new StreamWriter(wr.GetRequestStream());
                sw.Write(data);
                sw.Close();

                StreamReader sr           = new StreamReader(wr.GetResponse().GetResponseStream());
                string       jsonResponse = sr.ReadToEnd();

                sr.Close();

                sw.Dispose();
                sr.Dispose();

                if (jsonResponse.Contains("\"error_code\"")) // Proces the response for errors - a simple throw is used to convert the text error in to an exception
                {
                    throw new Exception(String.Format("Error calling facebook API!\nJSON: {0} \nAPI CALL: {1}", jsonResponse, apiCallUrl));
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception occurred in FacebookSocialConnector.Post processing User ID #" + ConnectionData.UserId + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace);
            }
        }
Exemplo n.º 3
0
        public static void ValidateUser(string ID, SocialConnectionType TypeID, string Token)
        {
            try
            {
                GamervineDataContext dContext = new GamervineDataContext();

                var gvUserId = from usc in dContext.UserSocialConnections
                               where usc.ConnectionUserId == ID && usc.Type == TypeID.GetHashCode()
                               select usc.UserId;

                if (gvUserId.Count() == 0)
                {
                    //User doesn't exist in the system, create new user records
                    User u = new User();
                    u.Email       = string.Empty;
                    u.UserId      = Guid.NewGuid().ToString();
                    u.State       = State.Active.GetHashCode();
                    u.CreatedDate = DateTime.UtcNow;

                    UserSocialConnection usc = new UserSocialConnection();
                    usc.ConnectionUserId       = ID;
                    usc.Token                  = Token;
                    usc.Type                   = TypeID.GetHashCode();
                    usc.UserId                 = u.UserId;
                    usc.UserSocialConnectionId = Guid.NewGuid().ToString();

                    dContext.Users.InsertOnSubmit(u);
                    dContext.UserSocialConnections.InsertOnSubmit(usc);

                    dContext.SubmitChanges();
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception occurred in bcUser.ValidateUser -> " + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace);
            }
        }
Exemplo n.º 4
0
        public static void ValidateUser(string ID, SocialConnectionType TypeID, string Token)
        {
            try
            {
                GamervineDataContext dContext = new GamervineDataContext();

                var gvUserId = from usc in dContext.UserSocialConnections
                               where usc.ConnectionUserId == ID && usc.Type == TypeID.GetHashCode()
                               select usc.UserId;

                if (gvUserId.Count() == 0)
                {
                    //User doesn't exist in the system, create new user records
                    User u = new User();
                    u.Email = string.Empty;
                    u.UserId = Guid.NewGuid().ToString();
                    u.State = State.Active.GetHashCode();
                    u.CreatedDate = DateTime.UtcNow;

                    UserSocialConnection usc = new UserSocialConnection();
                    usc.ConnectionUserId = ID;
                    usc.Token = Token;
                    usc.Type = TypeID.GetHashCode();
                    usc.UserId = u.UserId;
                    usc.UserSocialConnectionId = Guid.NewGuid().ToString();

                    dContext.Users.InsertOnSubmit(u);
                    dContext.UserSocialConnections.InsertOnSubmit(usc);

                    dContext.SubmitChanges();
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception occurred in bcUser.ValidateUser -> " + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace);
            }
        }