Esempio n. 1
0
        /// <summary>
        /// Get the Twitter response object for the friends
        /// </summary>
        /// <returns></returns>
        private TwitterResponse <TwitterUserCollection> GetTwitterFriends()
        {
            TwitterResponse <TwitterUserCollection> twitterResponse = new TwitterResponse <TwitterUserCollection>();

            if (Page.Cache[string.Format("TwitterFriends-{0}", this.ScreenName)] == null)
            {
                //create a authorization token of the user
                OAuthTokens tokens = new OAuthTokens();
                tokens.ConsumerKey       = this.ConsumerKey;
                tokens.ConsumerSecret    = this.ConsumerSecret;
                tokens.AccessToken       = this.AccessToken;
                tokens.AccessTokenSecret = this.AccessTokenSecret;

                //Set the query options
                FriendsOptions Friendoptions = new FriendsOptions();
                Friendoptions.ScreenName = this.ScreenName;
                Friendoptions.Cursor     = -1;

                //get the Following Object from the Twitter
                twitterResponse = TwitterFriendship.Friends(tokens, Friendoptions);
                HttpContext.Current.Cache.Insert(string.Format("TwitterFriends-{0}", this.ScreenName), twitterResponse, null, DateTime.Now.AddMinutes(Common.CACHEDURATION), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Normal, null);
            }
            else
            {
                twitterResponse = Page.Cache[string.Format("TwitterFriends-{0}", this.ScreenName)] as TwitterResponse <TwitterUserCollection>;
            }

            return(twitterResponse);
        }
Esempio n. 2
0
        private void getUserFriends(string username)
        {
            getWaitCursor();

            //FollowersOptions options = new FollowersOptions();

            //TwitterResponse<TwitterUserCollection> followers = TwitterFriendship.Friends(_authToken);
            TwitterResponse <TwitterUserCollection> friends = TwitterFriendship.Friends(_authToken);

            if (friends.Result == RequestResult.Success)
            {
                try
                {
                    int friendsNumber = friends.ResponseObject.Count;

                    for (int j = 0; j < friendsNumber; j++)
                    {
                        var result = friends.ResponseObject[j];

                        if (j == 99)
                        {
                            friends       = friends.ResponseObject.NextPage();
                            friendsNumber = friends.ResponseObject.Count;
                            //MessageBox.Show(friendsNumber.ToString());
                            j = 0;
                            continue;
                        }
                        ListViewItem friend = new ListViewItem();
                        //follower.Name = result.ScreenName;
                        friend.Uid = result.Id.ToString();
                        //MessageBox.Show(friend.Uid.ToString());
                        // follower.MouseDoubleClick += new MouseButtonEventHandler(ListViewFollower_Selected);

                        StackPanel stack = new StackPanel();;
                        stack.Width = 100;
                        //stack.Orientation = System.Windows.Controls.Orientation.Vertical;

                        Label lbl = new Label();
                        lbl.Content             = result.ScreenName;
                        lbl.Foreground          = Brushes.White;
                        lbl.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;


                        BitmapImage avatar = new BitmapImage();
                        avatar.BeginInit();
                        // Set properties.
                        avatar.CacheOption       = BitmapCacheOption.OnDemand;
                        avatar.CreateOptions     = BitmapCreateOptions.IgnoreColorProfile;
                        avatar.UriSource         = new Uri(result.ProfileImageLocation);
                        avatar.DecodePixelHeight = 48;
                        avatar.DecodePixelWidth  = 48;

                        // End initialization.
                        avatar.EndInit();

                        Image img = new Image();
                        img.Source = avatar;
                        img.Width  = 48;
                        img.Height = 48;
                        img.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;

                        stack.Children.Add(img);
                        //Console.WriteLine(result.ScreenName + ": img ->" + result.ProfileImageLocation);

                        stack.Children.Add(lbl);
                        friend.Content = stack;
                        listviewFollowers.Items.Add(friend);
                    }
                    //listviewFollowers.scro
                }

                catch (TwitterizerException e1)
                {
                    MessageBox.Show("Erro - " + e1);
                }
            }
            else
            {
                MessageBox.Show(friends.ErrorMessage);
            }

            //Number of followers added
            lblFollowers.Content = "Following " + listviewFollowers.Items.Count.ToString();
            getDefaultCursor();
        }