Esempio n. 1
0
        private static UserProfile UserProfileFromFBJson(JSONObject fbJsonObject, FBSocialProvider provider)
        {
            JSONObject soomlaJsonObject = new JSONObject();

            soomlaJsonObject.AddField(PJSONConsts.UP_PROVIDER, Provider.FACEBOOK.ToString());
            soomlaJsonObject.AddField(PJSONConsts.UP_PROFILEID, fbJsonObject["id"].str);
            string name = fbJsonObject ["name"].str;

            soomlaJsonObject.AddField(PJSONConsts.UP_USERNAME, name);
            string email = fbJsonObject ["email"] != null ? fbJsonObject ["email"].str : null;

            if (email == null)
            {
                email = Regex.Replace(name, @"\s+", ".") + "@facebook.com";
            }
            soomlaJsonObject.AddField(PJSONConsts.UP_EMAIL, email);
            soomlaJsonObject.AddField(PJSONConsts.UP_FIRSTNAME, fbJsonObject["first_name"].str);
            soomlaJsonObject.AddField(PJSONConsts.UP_LASTNAME, fbJsonObject["last_name"].str);
            soomlaJsonObject.AddField(PJSONConsts.UP_AVATAR, fbJsonObject["picture"]["data"]["url"].str);
            if (fbJsonObject["gender"] != null)
            {
                soomlaJsonObject.AddField(PJSONConsts.UP_GENDER, fbJsonObject["gender"].str);
            }
            if (fbJsonObject["languages"] != null && fbJsonObject["languages"].Count > 0 &&
                fbJsonObject["languages"][0] != null && fbJsonObject["languages"][0]["name"] != null)
            {
                soomlaJsonObject.AddField(PJSONConsts.UP_LANGUAGE, fbJsonObject["languages"][0]["name"].str);
            }
            if (fbJsonObject["location"] != null && fbJsonObject["location"]["name"] != null)
            {
                soomlaJsonObject.AddField(PJSONConsts.UP_LOCATION, fbJsonObject["location"]["name"].str);
            }

            if (provider != null)               //let us to know if method called during own profile receiving
            {
                Dictionary <String, JSONObject> extraDict = new Dictionary <String, JSONObject>();
                extraDict.Add("access_token", JSONObject.StringObject(FB.AccessToken));
                JSONObject permissionsObject = JSONObject.Create(JSONObject.Type.ARRAY);
                foreach (String permission in provider.permissions)
                {
                    permissionsObject.Add(permission);
                }
                extraDict.Add("permissions", permissionsObject);
                extraDict.Add("expiration_date", new JSONObject((FB.AccessTokenExpiresAt - new DateTime(1970, 1, 1)).TotalSeconds));
                soomlaJsonObject.AddField(PJSONConsts.UP_EXTRA, new JSONObject(extraDict));
            }

            UserProfile userProfile = new UserProfile(soomlaJsonObject);

            return(userProfile);
        }
		private static UserProfile UserProfileFromFBJson(JSONObject fbJsonObject, FBSocialProvider provider) {
			JSONObject soomlaJsonObject = new JSONObject ();
			soomlaJsonObject.AddField(PJSONConsts.UP_PROVIDER, Provider.FACEBOOK.ToString ());
			soomlaJsonObject.AddField(PJSONConsts.UP_PROFILEID, fbJsonObject["id"].str);
			string name = fbJsonObject ["name"].str;
			soomlaJsonObject.AddField(PJSONConsts.UP_USERNAME, name);
			string email = fbJsonObject ["email"] != null ? fbJsonObject ["email"].str : null;
			if (email == null) {
				email = Regex.Replace(name, @"\s+", ".") + "@facebook.com";
			}
			soomlaJsonObject.AddField(PJSONConsts.UP_EMAIL, email);
			soomlaJsonObject.AddField(PJSONConsts.UP_FIRSTNAME, fbJsonObject["first_name"].str);
			soomlaJsonObject.AddField(PJSONConsts.UP_LASTNAME, fbJsonObject["last_name"].str);
			soomlaJsonObject.AddField(PJSONConsts.UP_AVATAR, fbJsonObject["picture"]["data"]["url"].str);
			if (fbJsonObject["gender"] != null) {
				soomlaJsonObject.AddField(PJSONConsts.UP_GENDER, fbJsonObject["gender"].str);
			}
			if (fbJsonObject["languages"] != null && fbJsonObject["languages"].Count > 0 
			    && fbJsonObject["languages"][0] != null && fbJsonObject["languages"][0]["name"] != null) {
				soomlaJsonObject.AddField(PJSONConsts.UP_LANGUAGE, fbJsonObject["languages"][0]["name"].str);
			}
			if (fbJsonObject["location"] != null && fbJsonObject["location"]["name"] != null) {
				soomlaJsonObject.AddField(PJSONConsts.UP_LOCATION, fbJsonObject["location"]["name"].str);
			}

			if (provider != null) { //let us to know if method called during own profile receiving
				Dictionary<String, JSONObject> extraDict = new Dictionary<String, JSONObject>();
				extraDict.Add("access_token", JSONObject.StringObject(AccessToken.CurrentAccessToken.TokenString));
				JSONObject permissionsObject = JSONObject.Create(JSONObject.Type.ARRAY);
				foreach (String permission in provider.permissions) {
					permissionsObject.Add(permission);
				}
				extraDict.Add("permissions", permissionsObject);
				extraDict.Add("expiration_date", new JSONObject((AccessToken.CurrentAccessToken.ExpirationTime - new DateTime(1970, 1, 1)).TotalSeconds));
				soomlaJsonObject.AddField(PJSONConsts.UP_EXTRA, new JSONObject(extraDict));
			}

			UserProfile userProfile = new UserProfile(soomlaJsonObject);
			
			return userProfile;
		}
		private static UserProfile UserProfileFromFBJsonString(string fbUserJsonStr, FBSocialProvider provider) {
			return UserProfileFromFBJson(new JSONObject (fbUserJsonStr), provider);
		}
 private static UserProfile UserProfileFromFBJsonString(string fbUserJsonStr, FBSocialProvider provider)
 {
     return(UserProfileFromFBJson(new JSONObject(fbUserJsonStr), provider));
 }