Пример #1
0
        public List<Models.User> Get(bool invite = false)
        {
            List<Models.User> output = new List<Models.User>();
            Models.Service service = _db.User.FirstOrDefault(c => c.UserId == WebSecurity.CurrentUserId).Services.FirstOrDefault(c => c.Provider == "twitter");
            if (service != null)
            {
                TwitterService twitter = new TwitterService(Settings.Settings.TwitterConsumerKey, Settings.Settings.TwitterConsumerSecret, service.Token, service.TokenSecret);

                var friends = twitter.ListFriends().ToList();

                foreach (var friend in friends)
                {

                    var username = OAuthWebSecurity.GetUserName("twitter", friend.Id.ToString());
                    if (username != null && invite == false)
                    {
                        int Id = WebSecurity.GetUserId(username);
                        Models.User user = _db.User.FirstOrDefault(c => c.UserId == Id);
                        output.Add(user);

                    }
                    else if(username == null && invite == true)
                    {
                        output.Add(new Models.User { Id = friend.Id, Image=friend.ProfileImageUrl, Name=friend.ScreenName});

                    }

                }

            }
            return output;
        }
        public IEnumerable<ChannelContact> GetContacts()
        {
            var service = new TwitterService(ChannelHelper.ConsumerKey, ChannelHelper.ConsumerSecret, ChannelHelper.Token, ChannelHelper.TokenSecret);
            var result = service.ListFriends();

            foreach (var user in result)
            {
                var contact = new ChannelContact { IsSoft = true };

                contact.Profile.ChannelProfileKey = user.Id.ToString();
                contact.Person.Name = user.Name;
                contact.Profile.ScreenName = user.ScreenName;
                contact.Profile.SourceAddress = new SourceAddress(user.Id.ToString(), user.Name);
                contact.Profile.ProfileType = ProfileType.Social;
                contact.Profile.Url = user.Url;
                contact.Profile.Title = user.Description;
                contact.Profile.Location = user.Location;
                contact.Profile.ChannelAvatar = new ChannelAvatar();
                contact.Profile.ChannelAvatar.Url = user.ProfileImageUrl;

                yield return contact;
            }
        }