Ejemplo n.º 1
0
		public  List<LinqToTwitter.Status> GetTwitterData()
		{
			BTProgressHUD.Show();
			//has the user already authenticated from a previous session? see AccountStore.Create().Save() later
			IEnumerable<Xamarin.Auth.Account> accounts = AccountStore.Create().FindAccountsForService("Twitter");

			//check the account store for a valid account marked as "Twitter" and then hold on to it for future requests

			var cred = new LinqToTwitter.InMemoryCredentialStore();
			cred.ConsumerKey = loggedInAccount.Properties["oauth_consumer_key"];
			cred.ConsumerSecret = loggedInAccount.Properties["oauth_consumer_secret"];
			cred.OAuthToken = loggedInAccount.Properties["oauth_token"];
			cred.OAuthTokenSecret = loggedInAccount.Properties["oauth_token_secret"];
			var auth = new LinqToTwitter.PinAuthorizer()
			{
				CredentialStore = cred,
			};
			var TwitterCtx = new LinqToTwitter.TwitterContext(auth);
			Console.WriteLine(TwitterCtx.User);
			List<LinqToTwitter.Status> tl = 
				(from tweet in TwitterCtx.Status
					where tweet.Type == LinqToTwitter.StatusType.Home
					select tweet).ToList();
			BTProgressHUD.Dismiss();
			return tl;
			//Console.WriteLine("Tweets Returned: " + tl.Count.ToString());
		}
Ejemplo n.º 2
0
        async protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            if (MainActivity.Activities.ContainsKey("SearchTwitter"))
            {
                MainActivity.Activities["SearchTwitter"].Finish();
                MainActivity.Activities.Remove("SearchTwitter");
                MainActivity.Activities.Add("SearchTwitter", this);
            }
            else
            {
                MainActivity.Activities.Add("SearchTwitter", this);
            }
            //has the user already authenticated from a previous session? see AccountStore.Create().Save() later
            IEnumerable <Xamarin.Auth.Account> accounts = Xamarin.Auth.AccountStore.Create(this).FindAccountsForService("UndertheShopTwitApp");

            SearchTerm = Intent.GetStringExtra("keyword");
            shopID     = Intent.GetStringExtra("SHOP_ID_NUMBER");
            local      = Intent.GetStringExtra("Local");

            //check the account store for a valid account marked as "Twitter" and then hold on to it for future requests
            foreach (Xamarin.Auth.Account account in accounts)
            {
                loggedInAccount = account;
                break;
            }
            if (loggedInAccount == null)
            {
                Toast.MakeText(this, GetString(Resource.String.authfail), ToastLength.Short).Show();
                var next = new Intent(this.ApplicationContext, typeof(ShopInfoActivity));
                next.PutExtra("SHOP_ID_NUMBER", shopID);
                next.PutExtra("Local", local);
                StartActivity(next);
                Finish();
            }

            else
            {
                var cred = new LinqToTwitter.InMemoryCredentialStore();
                cred.ConsumerKey      = loggedInAccount.Properties["oauth_consumer_key"];
                cred.ConsumerSecret   = loggedInAccount.Properties["oauth_consumer_secret"];
                cred.OAuthToken       = loggedInAccount.Properties["oauth_token"];
                cred.OAuthTokenSecret = loggedInAccount.Properties["oauth_token_secret"];
                var auth0 = new LinqToTwitter.PinAuthorizer()
                {
                    CredentialStore = cred,
                };
                var TwitterCtx = new LinqToTwitter.TwitterContext(auth0);
                Console.WriteLine(TwitterCtx.User);
                _searches = await(from tweet in TwitterCtx.Search
                                  where (tweet.Type == SearchType.Search) &&
                                  (tweet.Query == SearchTerm)
                                  select tweet).ToListAsync();
                this.ListAdapter = new SearchAdapter(this, _searches[0].Statuses);
            }
        }
        public TwitterTimelineCompetitionSource(int checkInterval, string user, string consumerKey, string consumerSecret, string accessToken, string accessSecret)
            : base(checkInterval, "Twitter Source (" + user + ")")
        {
            _credentialStore = new InMemoryCredentialStore()
            {
                ConsumerKey = consumerKey,
                ConsumerSecret = consumerSecret,
                OAuthToken = accessToken,
                OAuthTokenSecret = accessSecret
            };

            _screenName = user;
        }
        public TwitterSearchCompetitionSource(int checkInterval, string query, List<String> blacklistedUsers, List<String> blacklistedTerms, bool locationSearch, string consumerKey, string consumerSecret, string accessToken, string accessSecret)
            : base(checkInterval, "Twitter Search (" + query + ")")
        {
            _query = query;
            _locationSearch = locationSearch;
            _blackListedUsers = blacklistedUsers;
            _blackListedTerms = blacklistedTerms;

            _credentialStore = new InMemoryCredentialStore()
            {
                ConsumerKey = consumerKey,
                ConsumerSecret = consumerSecret,
                OAuthToken = accessToken,
                OAuthTokenSecret = accessSecret
            };
        }
        IAuthorizer PerformAuthorization()
        {
            // validate that credentials are present
            if (string.IsNullOrWhiteSpace(twitterConsumerKey) 
                || string.IsNullOrWhiteSpace(twitterConsumerSecret)
                || string.IsNullOrWhiteSpace(twitterConsumerKeyDM) 
                || string.IsNullOrWhiteSpace(twitterConsumerSecretDM))
            {
                MessageBox.Show(@"Error while setting " +
                                    "App.config/appSettings. \n\n" +
                                    "You need to provide your twitterConsumerKey and twitterConsumerSecret in App.config \n" +
                                    "Please visit http://dev.twitter.com/apps for more info.\n");

                return null;
            }

            InMemoryCredentialStore credentialStore = null;
            if(needsDMPermissions)
            {
                credentialStore = new InMemoryCredentialStore()
                {
                    ConsumerKey = twitterConsumerKeyDM,
                    ConsumerSecret = twitterConsumerSecretDM
                };
            }
            else
            {
                credentialStore = new InMemoryCredentialStore()
                {
                    ConsumerKey = twitterConsumerKey,
                    ConsumerSecret = twitterConsumerSecret
                };
            }

            // configure the OAuth object
            var auth = new PinAuthorizer
            {
                CredentialStore = credentialStore,
                GoToTwitterAuthorization = pageLink => Process.Start(pageLink),
                GetPin = () =>
                {
                    // ugly hack
                    string pin = "";

                    Dispatcher.Invoke((Action)
                    (() =>
                        {
                            PinWindow pinw = new PinWindow();
                            pinw.Owner = this;
                            if (pinw.ShowDialog() == true)
                                pin = pinw.Pin;
                            else
                                pin = "";
                        }
                    ));

                    return pin;
                }
            };

            return auth;
        }