예제 #1
0
        private async Task <WinRtAuthorizer> Authenticate()
        {
            _credentials = await LocalDataCredentials.GetWinRtCredentialsAsync(ApplicationData.Current.LocalFolder);

            if (_credentials.ToString().Equals(",,,,,"))
            {
                _credentials.ConsumerKey    = "zPPDxXgf25WedMuVpYpw";
                _credentials.ConsumerSecret = "2Bad9VxQYzfsYDaowidBkoRBIq87wtjjFV8FAvcvV8";
                _credentials.AccessToken    = "32533776-uwuq1NLOaJSGdFH3qSrPjHp866I3lssiizrGQowXv";
            }
            _authorizer = new WinRtAuthorizer
            {
                Credentials    = _credentials,
                UseCompression = true,
                Callback       = new Uri("http://www.twittelytics.com")
            };
            if (!_authorizer.IsAuthorized)
            {
                Task <WinRtAuthorizer> task = _authorizer.AuthorizeAsync();
                await task.ContinueWith(t =>
                {
                    _authorizer.ScreenName = _credentials.ScreenName;
                    _authorizer.UserId     = _credentials.UserId;
                });

                if (_authorizer.IsAuthorized)
                {
                    return(task.Result);
                }
            }
            return(_authorizer);
        }
예제 #2
0
 public async Task AuthorizeAsync()
 {
     Task <WinRtAuthorizer> task = Authenticate();
     await task.ContinueWith(wrt =>
     {
         _authorizer = wrt.Result;
         if (_authorizer.IsAuthorized)
         {
             _credentials.Save();
         }
     });
 }
예제 #3
0
        /// <summary>
        /// Creates the client adn initializes the members that will request a Twitter authorization and
        /// perform search tasks.
        /// </summary>
        /// <param name="device">DirectX device.</param>
        /// <param name="factory">Imaging factory.</param>
        public TwitterClient(Device1 device, ImagingFactory2 factory)
        {
            this.authorizer = new WinRtAuthorizer()
            {
                Credentials = new LocalDataCredentials()
                {
#error Please create an application in Twitter and set your own consumer key and secret.
                    ConsumerKey    = null,
                    ConsumerSecret = null,
                },
                UseCompression = true,
                Callback       = new Uri("http://followercatcher.codeplex.com/"),
            };

            this.device         = device;
            this.factory        = factory;
            this.AvatarTextures = new List <Texture>();
            this.Tweets         = new Dictionary <string, TweetInfo>();

            LoadTexturesFromCache();
        }
예제 #4
0
        async void SearchButton_Click(object sender, RoutedEventArgs e)
        {
            // Linq2TwitterCredentials.txt is the default isolated store file name,
            // but you can change it and pass as an argument to LocalDataCredentials
            string fileName = "Linq2TwitterCredentials.txt";

            //
            // The code below demonstrates how to remove credentials from isolated storage
            //

            //var files = await ApplicationData.Current.LocalFolder.GetFilesAsync();
            //if (files.Any(storFile => storFile.Name == fileName))
            //{
            //    var file = await ApplicationData.Current.LocalFolder.GetFileAsync(fileName);
            //    await file.DeleteAsync();
            //}

            //var credentials = new LocalDataCredentials(fileName);
            //await credentials.ClearAsync();

            var auth = new WinRtAuthorizer
            {
                Credentials = new LocalDataCredentials(fileName)
                {
                    ConsumerKey    = "",
                    ConsumerSecret = ""
                },
                UseCompression = true,
                Callback       = new Uri("http://linqtotwitter.codeplex.com/")
            };

            //
            // Comment above and uncomment below to test WinRtApplicationOnlyAuthorizer
            //

            //var auth = new WinRtApplicationOnlyAuthorizer
            //{
            //    Credentials = new InMemoryCredentials
            //    {
            //        ConsumerKey = "",
            //        ConsumerSecret = ""
            //    }
            //};

            if (auth != null && !auth.IsAuthorized)
            {
                await auth.AuthorizeAsync();
            }

            var twitterCtx = new TwitterContext(auth);

            (from search in twitterCtx.Search
             where search.Type == SearchType.Search &&
             search.Query == SearchTextBox.Text
             select search)
            .MaterializedAsyncCallback(
                async response =>
                await Dispatcher.RunAsync(
                    CoreDispatcherPriority.Normal,
                    async() =>
            {
                Search searchResponse = response.State.Single();
                string message        =
                    string.Format(
                        "Search returned {0} statuses",
                        searchResponse.Statuses.Count);

                await new MessageDialog(message, "Search Complete").ShowAsync();
            }));
        }
예제 #5
0
 public void Logout()
 {
     _credentials.Clear();
     _authorizer  = null;
     _credentials = null;
 }