Ejemplo n.º 1
0
        private void fillUserInfo(FacebookSocialUserInfo userInfo)
        {
            var responseObj = WebClient.GetJson(GETUSERINFO_BASEURL.Args(APIGraphVersion), new WebClient.RequestParams(this)
            {
                Method          = HTTPRequestMethod.GET,
                QueryParameters = new Dictionary <string, string>()
                {
                    { ACCESSTOKEN_PARAMNAME, userInfo.AccessToken },
                    { GETUSERINFO_FIELDS_PARAMNAME, FILL_USER_INFO_FIELDS }
                }
            });

            userInfo.LoginState = SocialLoginState.LoggedIn;
            userInfo.ID         = responseObj[USER_ID_PARAMNAME].AsString();
            userInfo.UserName   = responseObj[USER_NAME_PARAMNAME].AsString();
            userInfo.Email      = responseObj[USER_EMAIL_PARAMNAME].AsString();
            userInfo.FirstName  = responseObj[USER_FIRSTNAME_PARAMNAME].AsString();
            userInfo.LastName   = responseObj[USER_LASTNAME_PARAMNAME].AsString();
            userInfo.MiddleName = responseObj[USER_MIDDLENAME_PARAMNAME].AsString();

            var genderStr = responseObj[USER_GENDER_PARAMNAME].AsString();

            if (genderStr == USER_GENDER_MALE)
            {
                userInfo.Gender = Gender.MALE;
            }
            else if (genderStr == USER_GENDER_FEMALE)
            {
                userInfo.Gender = Gender.FEMALE;
            }

            var      birthDateStr = responseObj[USER_BIRTHDAY_PARAMNAME].AsString();
            DateTime birthDate;

            if (DateTime.TryParseExact(birthDateStr, "MM/DD/YYYY",
                                       System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out birthDate))
            {
                userInfo.BirthDate = birthDate;
            }

            userInfo.Locale         = responseObj[USER_LOCALE_PARAMNAME].AsString();
            userInfo.TimezoneOffset = ((int)responseObj[USER_TIMEZONE_PARAMNAME]) * 60 * 60;

            var picObj = WebClient.GetJson(GET_USER_PICTURE_URL_PATTERN.Args(APIGraphVersion, userInfo.ID), new WebClient.RequestParams(this)
            {
                Method          = HTTPRequestMethod.GET,
                QueryParameters = new Dictionary <string, string>()
                {
                    { ACCESSTOKEN_PARAMNAME, userInfo.AccessToken }
                }
            });
            var imgInfo = picObj[USER_PICTURE_DATA_PARAMNAME] as JSONDataMap;

            if (imgInfo != null)
            {
                userInfo.PictureLink = imgInfo[USER_PICTURE_URL_PARAMNAME].AsString();
            }
        }
Ejemplo n.º 2
0
        protected override void DoPostMessage(string text, SocialUserInfo userInfo)
        {
            if (userInfo.LoginState != SocialLoginState.LoggedIn)
            {
                return;
            }

            FacebookSocialUserInfo fbUserInfo = userInfo as FacebookSocialUserInfo;

            publish(fbUserInfo.ID, fbUserInfo.AccessToken, text);
        }
Ejemplo n.º 3
0
        private void fillUserInfo(FacebookSocialUserInfo userInfo)
        {
            var fields = string.Join(",", USER_ID_PARAMNAME, USER_EMAIL_PARAMNAME, USER_NAME_PARAMNAME, USER_FIRSTNAME_PARAMNAME,
                                     USER_LASTNAME_PARAMNAME, USER_MIDDLENAME_PARAMNAME, USER_GENDER_PARAMNAME, USER_BIRTHDAY_PARAMNAME,
                                     USER_LOCALE_PARAMNAME, USER_TIMEZONE_PARAMNAME, USER_PICTURE_PARAMNAME);

            dynamic responseObj = WebClient.GetJsonAsDynamic(GETUSERINFO_BASEURL, new WebClient.RequestParams(this)
            {
                Method  = HTTPRequestMethod.GET,
                Headers = new Dictionary <string, string>()
                {
                    { ACCESSTOKEN_PARAMNAME, userInfo.AccessToken },
                    { GETUSERINFO_FIELDS_PARAMNAME, fields }
                }
            });

            userInfo.LoginState = SocialLoginState.LoggedIn;
            userInfo.ID         = responseObj[USER_ID_PARAMNAME];
            userInfo.UserName   = responseObj[USER_NAME_PARAMNAME];
            userInfo.Email      = responseObj[USER_EMAIL_PARAMNAME];
            userInfo.FirstName  = responseObj[USER_FIRSTNAME_PARAMNAME];
            userInfo.LastName   = responseObj[USER_LASTNAME_PARAMNAME];
            userInfo.MiddleName = responseObj[USER_MIDDLENAME_PARAMNAME];

            var genderStr = responseObj[USER_GENDER_PARAMNAME];

            if (genderStr == USER_GENDER_MALE)
            {
                userInfo.Gender = Gender.MALE;
            }
            else if (genderStr == USER_GENDER_MALE)
            {
                userInfo.Gender = Gender.FEMALE;
            }

            var      birthDateStr = responseObj[USER_BIRTHDAY_PARAMNAME];
            DateTime birthDate;

            if (DateTime.TryParseExact(birthDateStr, "MM/DD/YYYY",
                                       System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out birthDate))
            {
                userInfo.BirthDate = birthDate;
            }

            userInfo.Locale         = responseObj[USER_LOCALE_PARAMNAME];
            userInfo.TimezoneOffset = ((int)responseObj[USER_TIMEZONE_PARAMNAME]) * 60 * 60;

            dynamic picObj = WebClient.GetJsonAsDynamic(GET_USER_PICTURE_URL_PATTERN.Args(userInfo.ID), new WebClient.RequestParams(this));

            userInfo.PictureLink = picObj[USER_PICTURE_DATA_PARAMNAME][USER_PICTURE_URL_PARAMNAME];
        }
Ejemplo n.º 4
0
        public void SerializeDeserializeFB()
        {
            using(var app = new ApplicationModel.TestApplication(m_RootCfg))
              {
            var ui = new FacebookSocialUserInfo(Facebook.Instance);

            initSocialUserInfo(ui);

            ui.UserName = "******";

            var s = ui.SerializeToString();
            var ui1 = SocialUserInfo.DeserializeFromString<FacebookSocialUserInfo>(s);
            Assert.AreEqual(ui, ui1);
              }
        }
Ejemplo n.º 5
0
        protected override void DoObtainTokens(SocialUserInfo userInfo, JSONDataMap request, string returnPageURL)
        {
            var code = request[ACCESSTOKEN_CODE_PARAMNAME].AsString();

            if (code.IsNullOrWhiteSpace())
            {
                throw new NFXException(StringConsts.ARGUMENT_ERROR + GetType().Name + ".GetUserInfo(request should contain code)");
            }

            FacebookSocialUserInfo fbUserInfo = userInfo as FacebookSocialUserInfo;

            string returnURL = PrepareReturnURLParameter(returnPageURL);

            fbUserInfo.AccessToken = getAccessToken(code, returnURL);
        }
Ejemplo n.º 6
0
        protected override void DoObtainTokens(SocialUserInfo userInfo, JSONDataMap request, string returnPageURL)
        {
            var code = request[ACCESSTOKEN_CODE_PARAMNAME].AsString();

            if (code.IsNullOrWhiteSpace())
            {
                throw new NFXException(StringConsts.ARGUMENT_ERROR + GetType().Name + ".GetUserInfo(request should contain code)");
            }

            FacebookSocialUserInfo fbUserInfo = userInfo as FacebookSocialUserInfo;

            var uri = new Uri(returnPageURL);

            fbUserInfo.AccessToken = getAccessToken(code, Uri.EscapeDataString(uri.GetLeftPart(UriPartial.Path)));
        }
Ejemplo n.º 7
0
        private void fillUserInfo(FacebookSocialUserInfo userInfo)
        {
          var fields = string.Join(",", USER_ID_PARAMNAME, USER_EMAIL_PARAMNAME, USER_NAME_PARAMNAME, USER_FIRSTNAME_PARAMNAME,
            USER_LASTNAME_PARAMNAME, USER_MIDDLENAME_PARAMNAME, USER_GENDER_PARAMNAME, USER_BIRTHDAY_PARAMNAME,
            USER_LOCALE_PARAMNAME, USER_TIMEZONE_PARAMNAME, USER_PICTURE_PARAMNAME);

          dynamic responseObj = WebClient.GetJson(GETUSERINFO_BASEURL, this, HTTPRequestMethod.GET, new Dictionary<string, string>() {
            {ACCESSTOKEN_PARAMNAME, userInfo.AccessToken},
            {GETUSERINFO_FIELDS_PARAMNAME, fields}
          });

          userInfo.LoginState = SocialLoginState.LoggedIn;
          userInfo.ID = responseObj[USER_ID_PARAMNAME];
          userInfo.UserName = responseObj[USER_NAME_PARAMNAME];
          userInfo.Email = responseObj[USER_EMAIL_PARAMNAME];
          userInfo.FirstName = responseObj[USER_FIRSTNAME_PARAMNAME];
          userInfo.LastName = responseObj[USER_LASTNAME_PARAMNAME];
          userInfo.MiddleName = responseObj[USER_MIDDLENAME_PARAMNAME];

          var genderStr = responseObj[USER_GENDER_PARAMNAME];
          if (genderStr == USER_GENDER_MALE)
            userInfo.Gender = Gender.MALE;
          else if (genderStr == USER_GENDER_MALE)
            userInfo.Gender = Gender.FEMALE;

          var birthDateStr = responseObj[USER_BIRTHDAY_PARAMNAME];
          DateTime birthDate;
          if (DateTime.TryParseExact(birthDateStr, "MM/DD/YYYY", 
            System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out birthDate))
              userInfo.BirthDate = birthDate;

          userInfo.Locale = responseObj[USER_LOCALE_PARAMNAME];
          userInfo.TimezoneOffset = ((int)responseObj[USER_TIMEZONE_PARAMNAME]) * 60 * 60;

          userInfo.PictureLink = responseObj[USER_PICTURE_PARAMNAME][USER_PICTURE_DATA_PARAMNAME][USER_PICTURE_URL_PARAMNAME];
        }