public override List <Contact> GetContacts() { Token token = ConnectionToken; List <Contact> contacts = new List <Contact>(); string response = ""; try { logger.Debug("Executing contacts feed"); Stream responseStream = AuthenticationStrategy.ExecuteFeed(ContactsEndpoint, this, token, TRANSPORT_METHOD.GET).GetResponseStream(); response = new StreamReader(responseStream).ReadToEnd(); } catch { throw; } try { JArray contactsJson = JArray.Parse(JObject.Parse(response).SelectToken("entry").ToString()); if (contactsJson.Count > 0) { contactsJson.ToList().ForEach(person => contacts.Add(new Contact() { ID = person.SelectToken("person.id") != null ? person.SelectToken("person.id").ToString().Replace("\"", "") : "", ProfileURL = person.SelectToken("person.profileUrl").ToString().Replace("\"", ""), Name = person.SelectToken("person.name.givenName") != null ? person.SelectToken("person.name.givenName").ToString() : "" + " " + person.SelectToken("person.name.familyName") != null ? person.SelectToken("person.name.familyName").ToString().Replace("\"", "") : "" })); } logger.Info("Contacts successfully received"); } catch (Exception ex) { logger.Error(ErrorMessages.ContactsParsingError(response), ex); throw new DataParsingException(ErrorMessages.ContactsParsingError(response), ex); } return(contacts.ToList()); }
public override List <Contact> GetContacts() { Token token = ConnectionToken; List <Contact> contacts = new List <Contact>(); string response = ""; try { logger.Debug("Executing contacts feed"); Stream responseStream = AuthenticationStrategy.ExecuteFeed(ContactsEndpoint + "?access_token=" + token.AccessToken, null, token, TRANSPORT_METHOD.GET).GetResponseStream(); response = new StreamReader(responseStream).ReadToEnd(); } catch { throw; } try { JObject contactsJson = JObject.Parse(response); contactsJson.SelectToken("data").ToList().ForEach(x => { contacts.Add(new Contact() { ID = x.SelectToken("id").ToString(), Name = getName(x) }); } ); logger.Info("Contacts successfully received"); return(contacts); } catch (Exception ex) { logger.Error(ErrorMessages.ContactsParsingError(response), ex); throw new DataParsingException(ErrorMessages.ContactsParsingError(response), ex); } }
private List <Contact> Friends(string friendUserIDs, Token token) { string lookupUrl = "http://api.twitter.com/1/users/lookup.json?user_id=" + friendUserIDs; OAuthHelper helper = new OAuthHelper(); string friendsData = ""; try { Stream responseStream = AuthenticationStrategy.ExecuteFeed(lookupUrl, this, token, TRANSPORT_METHOD.GET).GetResponseStream(); friendsData = new StreamReader(responseStream).ReadToEnd(); } catch { throw; } List <Contact> friends = new List <Contact>(); try { JArray j = JArray.Parse(friendsData); j.ToList().ForEach(f => friends.Add( new Contact() { Name = (string)f["name"], ID = (string)f["id_str"], ProfileURL = "http://twitter.com/#!/" + (string)f["screen_name"] })); } catch { throw; } return(friends.ToList <Contact>()); }
//****** OPERATIONS public override UserProfile GetProfile() { Token token = ConnectionToken; UserProfile profile = new UserProfile(ProviderType); string response = ""; //If token already has profile for this provider, we can return it to avoid a call if (token.Profile.IsSet || !IsProfileSupported) { return(token.Profile); } var provider = ProviderFactory.GetProvider(token.Provider); if (GetScope().ToLower().Contains("https://www.googleapis.com/auth/userinfo.profile")) { try { logger.Debug("Executing profile feed"); Stream responseStream = AuthenticationStrategy.ExecuteFeed(ProfileEndpoint, this, token, TRANSPORT_METHOD.GET).GetResponseStream(); response = new StreamReader(responseStream).ReadToEnd(); } catch { throw; } try { JObject profileJson = JObject.Parse(response); //{"entry":{"profileUrl":"https://plus.google.com/103908432244378021535","isViewer":true,"id":"103908432244378021535", // "name":{"formatted":"deepak Aggarwal","familyName":"Aggarwal","givenName":"deepak"}, // "thumbnailUrl":"http://www.,"urls":[{"value":"https://plus.google.com/103908432244378021535","type":"profile"}], // "photos":[{"value":"http://www.google.com/ig/c/photos/public/AIbEiAIAAABDCJ_d1payzeKeNiILdmNhcmRfcGhvdG8qKGFjM2RmMzQ1ZDc4Nzg5NmI5NmFjYTc1NDNjOTA3MmQ5MmNmOTYzZWIwAe0HZMa7crOI_laYBG7LxYvlAvqe","type":"thumbnail"}],"displayName":"deepak Aggarwal"}} profile.Provider = ProviderType; profile.ID = profileJson.Get("id"); profile.ProfileURL = profileJson.Get("link"); profile.FirstName = profileJson.Get("given_name"); profile.LastName = profileJson.Get("family_name"); profile.ProfilePictureURL = profileJson.Get("picture"); profile.GenderType = Utility.ParseGender(profileJson.Get("gender")); } catch (Exception ex) { logger.Error(ErrorMessages.ProfileParsingError(response), ex); throw new DataParsingException(response, ex); } } else { profile.FirstName = token.ResponseCollection["openid.ext1.value.firstname"]; profile.LastName = token.ResponseCollection["openid.ext1.value.lastname"]; } profile.Email = token.ResponseCollection.Get("openid.ext1.value.email"); profile.Country = token.ResponseCollection.Get("openid.ext1.value.country"); profile.Language = token.ResponseCollection.Get("openid.ext1.value.language"); profile.IsSet = true; token.Profile = profile; logger.Info("Profile successfully received"); return(profile); }
public virtual WebResponse ExecuteFeed(string feedURL, TRANSPORT_METHOD transportMethod, byte[] content = null, Dictionary <string, string> headers = null) { if (AuthenticationStrategy != null) { return(AuthenticationStrategy.ExecuteFeed(feedURL, (IProvider)this, GetConnectionToken(), transportMethod, content, headers)); } else { throw new NotImplementedException("This method is not implemented!;"); } }
//****** OPERATIONS public override UserProfile GetProfile() { Token token = SocialAuthUser.GetCurrentUser().GetConnection(this.ProviderType).GetConnectionToken(); UserProfile profile = new UserProfile(ProviderType); string response = ""; //If token already has profile for this provider, we can return it to avoid a call if (token.Profile.IsSet) { logger.Debug("Profile successfully returned from session"); return(token.Profile); } try { logger.Debug("Executing Profile feed"); string profileUrl = ProfileEndpoint + "?user_id=" + token.Profile.ID; Stream responseStream = AuthenticationStrategy.ExecuteFeed(profileUrl, this, token, TRANSPORT_METHOD.GET).GetResponseStream(); response = new StreamReader(responseStream).ReadToEnd(); } catch { throw; } try { JObject profileJson = JObject.Parse(response); profile.ID = profileJson.Get("id_str"); profile.FirstName = profileJson.Get("name"); profile.Country = profileJson.Get("location"); profile.DisplayName = profileJson.Get("screen_name"); //profile.Email = not provided profile.Language = profileJson.Get("lang"); profile.ProfilePictureURL = profileJson.Get("profile_image_url"); profile.IsSet = true; token.Profile = profile; logger.Info("Profile successfully received"); } catch (Exception ex) { logger.Error(ErrorMessages.ProfileParsingError(response), ex); throw new DataParsingException(ErrorMessages.ProfileParsingError(response), ex); } return(profile); }
public override List <Contact> GetContacts() { Token token = ConnectionToken; //If only OpenID is used and also there is no scope for contacts, return blank list straight away if (string.IsNullOrEmpty(token.AccessToken) || !(GetScope().ToLower().Contains("/m8/feeds"))) { return(new List <Contact>()); } IEnumerable <Contact> contacts; string response = ""; try { logger.Debug("Executing contacts feed"); Stream responseStream = AuthenticationStrategy.ExecuteFeed(ContactsEndpoint, this, token, TRANSPORT_METHOD.GET).GetResponseStream(); response = new StreamReader(responseStream).ReadToEnd(); } catch { throw; } try { XDocument contactsXML = XDocument.Parse(response); XNamespace xn = "http://schemas.google.com/g/2005"; contacts = from c in contactsXML.Descendants(contactsXML.Root.GetDefaultNamespace() + "entry") select new Contact() { ID = c.Element(contactsXML.Root.GetDefaultNamespace() + "id").Value, Name = c.Element(contactsXML.Root.GetDefaultNamespace() + "title").Value, Email = (c.Element(xn + "email") == null) ? "" : c.Element(xn + "email").Attribute("address").Value, ProfilePictureURL = "" }; logger.Info("Contacts successfully received"); } catch (Exception ex) { logger.Error(ErrorMessages.ContactsParsingError(response), ex); throw new DataParsingException(ErrorMessages.ContactsParsingError(response), ex); } return(contacts.ToList()); }
//****** OPERATIONS public override UserProfile GetProfile() { Token token = ConnectionToken; string response = ""; //If token already has profile for this provider, we can return it to avoid a call if (token.Profile.IsSet) { return(token.Profile); } try { logger.Debug("Executing Profile feed"); Stream responseStream = AuthenticationStrategy.ExecuteFeed(ProfileEndpoint, this, token, TRANSPORT_METHOD.GET).GetResponseStream(); response = new StreamReader(responseStream).ReadToEnd(); } catch { throw; } try { JObject profileJson = JObject.Parse(response); token.Profile.ID = profileJson.Get("person.id"); token.Profile.FirstName = profileJson.Get("person.name.givenName"); token.Profile.LastName = profileJson.Get("person.name.familyName"); token.Profile.Country = profileJson.Get("person.location"); token.Profile.Language = profileJson.Get("person.lang"); token.Profile.ProfilePictureURL = profileJson.Get("person.thumbnailUrl"); token.Profile.IsSet = true; logger.Info("Profile successfully received"); } catch (Exception ex) { logger.Error(ErrorMessages.ProfileParsingError(response), ex); throw new DataParsingException(ErrorMessages.ProfileParsingError(response), ex); } return(token.Profile); }
public override List <Contact> GetContacts() { Token token = ConnectionToken; List <Contact> contacts = new List <Contact>(); string response = ""; try { Stream responseStream = AuthenticationStrategy.ExecuteFeed(ContactsEndpoint, this, token, TRANSPORT_METHOD.GET).GetResponseStream(); response = new StreamReader(responseStream).ReadToEnd(); } catch { throw; } try { XDocument contactsXml = XDocument.Parse(response); IEnumerable <XElement> persons = contactsXml.Root.Elements("person"); foreach (var person in persons) { contacts.Add(new Contact() { ID = person.Element("id") != null ? person.Element("id").Value : "", ProfileURL = person.Element("public-profile-url") != null ? person.Element("public-profile-url").Value : "", Name = person.Element("first-name") != null ? person.Element("first-name").Value : "" + " " + person.Element("first-name") != null ? person.Element("last-name").Value : "" }); } logger.Info("Contacts successfully received"); } catch (Exception ex) { logger.Error(ErrorMessages.ContactsParsingError(response), ex); throw new DataParsingException(ErrorMessages.ContactsParsingError(response), ex); } return(contacts); }
public override WebResponse ExecuteFeed(string feedUrl, TRANSPORT_METHOD transportMethod) { return(AuthenticationStrategy.ExecuteFeed(feedUrl, this, ConnectionToken, transportMethod)); }
//****** OPERATIONS public override UserProfile GetProfile() { Token token = ConnectionToken; UserProfile profile = new UserProfile(ProviderType); string response = ""; //If token already has profile for this provider, we can return it to avoid a call if (token.Profile.IsSet) { return(token.Profile); } try { logger.Debug("Executing Profile feed"); Stream responseStream = AuthenticationStrategy.ExecuteFeed( string.Format(ProfileEndpoint, token.ResponseCollection["xoauth_yahoo_guid"]), this, token, TRANSPORT_METHOD.GET).GetResponseStream(); response = new StreamReader(responseStream).ReadToEnd(); } catch { throw; } try { XDocument xDoc = XDocument.Parse(response); XNamespace xn = xDoc.Root.GetDefaultNamespace(); profile.ID = xDoc.Root.Element(xn + "guid") != null?xDoc.Root.Element(xn + "guid").Value : string.Empty; profile.FirstName = xDoc.Root.Element(xn + "givenName") != null?xDoc.Root.Element(xn + "givenName").Value : string.Empty; profile.LastName = xDoc.Root.Element(xn + "familyName") != null?xDoc.Root.Element(xn + "familyName").Value : string.Empty; profile.DateOfBirth = xDoc.Root.Element(xn + "birthdate") != null?xDoc.Root.Element(xn + "birthdate").Value : "/"; profile.DateOfBirth = xDoc.Root.Element(xn + "birthyear") != null ? "/" + xDoc.Root.Element(xn + "birthyear").Value : "/"; profile.Country = xDoc.Root.Element(xn + "location") != null?xDoc.Root.Element(xn + "location").Value : string.Empty; profile.ProfileURL = xDoc.Root.Element(xn + "profileUrl") != null?xDoc.Root.Element(xn + "profileUrl").Value : string.Empty; profile.ProfilePictureURL = xDoc.Root.Element(xn + "image") != null?xDoc.Root.Element(xn + "image").Element(xn + "imageUrl").Value : string.Empty; profile.Language = xDoc.Root.Element(xn + "lang") != null?xDoc.Root.Element(xn + "lang").Value : string.Empty; if (xDoc.Root.Element(xn + "gender") != null) { profile.GenderType = Utility.ParseGender(xDoc.Root.Element(xn + "gender").Value); } if (string.IsNullOrEmpty(profile.FirstName)) { profile.FirstName = token.ResponseCollection["openid.ax.value.firstname"]; } if (string.IsNullOrEmpty(profile.FirstName)) { profile.LastName = token.ResponseCollection["openid.ax.value.lastname"]; } profile.Email = token.ResponseCollection.Get("openid.ax.value.email"); profile.Country = token.ResponseCollection.Get("openid.ax.value.country"); profile.Language = token.ResponseCollection.Get("openid.ax.value.language"); profile.IsSet = true; profile.IsSet = true; token.Profile = profile; logger.Info("Profile successfully received"); } catch (Exception ex) { logger.Error(ErrorMessages.ProfileParsingError(response), ex); throw new DataParsingException(ErrorMessages.ProfileParsingError(response), ex); } return(profile); }
public override List <Contact> GetContacts() { Token token = ConnectionToken; List <Contact> contacts = new List <Contact>(); string response = ""; try { logger.Debug("Executing contacts feed"); Stream responseStream = AuthenticationStrategy.ExecuteFeed( string.Format(ContactsEndpoint, token.ResponseCollection["xoauth_yahoo_guid"]), this, token, TRANSPORT_METHOD.GET).GetResponseStream(); response = new StreamReader(responseStream).ReadToEnd(); } catch { throw; } try { //Extract information from XML XDocument xdoc = XDocument.Parse(response); XNamespace xn = xdoc.Root.GetDefaultNamespace(); XNamespace attxn = "http://www.yahooapis.com/v1/base.rng"; xdoc.Root.Descendants(xdoc.Root.GetDefaultNamespace() + "contact").ToList().ForEach(x => { IEnumerable <XElement> contactFields = x.Elements(xn + "fields").ToList(); foreach (var field in contactFields) { Contact contact = new Contact(); if (field.Attribute(attxn + "uri").Value.Contains("/yahooid/")) { //contact.Name = field.Element(xn + "value").Value; //contact.Email = field.Element(xn + "value").Value + "@yahoo.com"; } else if (field.Attribute(attxn + "uri").Value.Contains("/name/")) { //Contact c = contacts.Last<Contact>(); //c.Name = field.Element(xn + "value").Element(xn + "givenName").Value + " " + field.Element(xn + "value").Element(xn + "familyName").Value; //contacts[contacts.Count - 1] = c; //continue; } else if (field.Attribute(attxn + "uri").Value.Contains("/email/")) { contact.Name = field.Element(xn + "value").Value.Replace("@yahoo.com", ""); contact.Email = field.Element(xn + "value").Value; } if (!string.IsNullOrEmpty(contact.Name) && !contacts.Exists(y => y.Email == contact.Email)) { contacts.Add(contact); } } }); logger.Info("Contacts successfully received"); } catch (Exception ex) { logger.Error(ErrorMessages.ContactsParsingError(response), ex); throw new DataParsingException(ErrorMessages.ContactsParsingError(response), ex); } return(contacts); }
//****** OPERATIONS public override UserProfile GetProfile() { Token token = ConnectionToken; string response = ""; //If token already has profile for this provider, we can return it to avoid a call if (token.Profile.IsSet) { logger.Debug("Profile successfully returned from session"); return(token.Profile); } try { logger.Debug("Executing Profile feed"); Stream responseStream = AuthenticationStrategy.ExecuteFeed(ProfileEndpoint, this, token, TRANSPORT_METHOD.GET).GetResponseStream(); response = new StreamReader(responseStream).ReadToEnd(); } catch { throw; } try { XDocument profileXml = XDocument.Parse(response); XElement person = profileXml.Element("person"); token.Profile.ID = person.Element("id") != null?person.Element("id").Value : ""; token.Profile.ProfileURL = "http://www.linkedin.com/profile/view?id=" + person.Element("id").Value; token.Profile.FirstName = person.Element("first-name") != null?person.Element("first-name").Value : ""; token.Profile.LastName = person.Element("first-name") != null?person.Element("last-name").Value : ""; token.Profile.ProfilePictureURL = person.Element("picture-url") != null?person.Element("picture-url").Value : ""; token.Profile.Email = person.Element("email-address") != null?person.Element("email-address").Value : ""; if (person.Element("date-of-birth") != null) { string d = person.Element("date-of-birth").Element("day") == null ? "" : person.Element("date-of-birth").Element("day").Value; string m = person.Element("date-of-birth").Element("month") == null ? "" : person.Element("date-of-birth").Element("month").Value; string y = person.Element("date-of-birth").Element("year") == null ? "" : person.Element("date-of-birth").Element("year").Value; token.Profile.DateOfBirth = string.Join("/", d, m, y); } if (person.Element("location") != null) { person.Element("location").Elements().ToList().ForEach( x => token.Profile.Country += x.Value); } token.Profile.IsSet = true; logger.Info("Profile successfully received"); } catch (Exception ex) { logger.Error(ErrorMessages.ProfileParsingError(response), ex); throw new DataParsingException(ErrorMessages.ProfileParsingError(response), ex); } return(token.Profile); }
public override WebResponse ExecuteFeed(string feedUrl, TRANSPORT_METHOD transportMethod) { logger.Debug("Calling execution of " + feedUrl); return(AuthenticationStrategy.ExecuteFeed(feedUrl, this, ConnectionToken, transportMethod)); }
public override WebResponse ExecuteFeed(string feedUrl, TRANSPORT_METHOD transportMethod) { return(AuthenticationStrategy.ExecuteFeed(feedUrl, this, SocialAuthUser.GetCurrentUser().GetConnection(ProviderType).GetConnectionToken(), transportMethod)); }
public override List <BusinessObjects.Contact> GetContacts() { List <Contact> contacts = new List <Contact>(); string response = ""; List <string> sets = new List <string>(); Token token = SocialAuthUser.GetCurrentUser().GetConnection(this.ProviderType).GetConnectionToken(); string friendsUrl = string.Format(ContactsEndpoint, token.Profile.Email); try { logger.Debug("Executing contacts feed"); Stream responseStream = AuthenticationStrategy.ExecuteFeed(friendsUrl, this, token, TRANSPORT_METHOD.GET).GetResponseStream(); response = new StreamReader(responseStream).ReadToEnd(); } catch { throw; } try { string friendIDs = ""; var friends = JObject.Parse(response).SelectToken("ids").Children().ToList(); friendIDs = ""; foreach (var s in friends) { friendIDs += (s.ToString() + ","); } char[] arr = friendIDs.ToArray <char>(); var iEnumerator = arr.GetEnumerator(); int counter = 0; string temp = ""; while (iEnumerator.MoveNext()) { if (iEnumerator.Current.ToString() == ",") { counter += 1; } if (counter == 100) { sets.Add(temp); temp = ""; counter = 0; continue; } temp += iEnumerator.Current; } if (temp != "") { sets.Add(temp); } } catch (Exception ex) { logger.Error(ErrorMessages.ContactsParsingError(response), ex); throw new DataParsingException(ErrorMessages.ContactsParsingError(response), ex); } foreach (string set in sets) { contacts.AddRange(Friends(set, token)); } logger.Info("Contacts successfully received"); return(contacts); }