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;
 }
 private async Task AuthorizeAsyncResult()
 {
     Task<WinRtAuthorizer> task = Authenticate();
     await task.ContinueWith(wrt =>
     {
         _authorizer = wrt.Result;
         if (_authorizer.IsAuthorized)
         {
             _credentials.Save();
         }
     });
 }
 public void Logout()
 {
     _credentials.Clear();
     _authorizer = null;
     _credentials = null;
 }
示例#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();
                        }));
        }