Thứ Sáu, 13 tháng 2, 2015

Chạy trong UI thread window phone store app

CoreDispatcher dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { });

Thứ Năm, 12 tháng 2, 2015

Các link hướng dẫn custom button , control

http://www.geekchamp.com/tips/custom-styles-and-templates-in-windows-phone-textbox
http://www.geekchamp.com/tips/custom-styles-and-templates-in-windows-phone-textbox
http://nirmitk26.blogspot.com/2011/02/round-button-in-windows-phone-7.html

Thứ Sáu, 6 tháng 2, 2015

Tương tác dropbox trong window phone

_ Download thư viện dropnet:http://dkdevelopment.net/what-im-doing/dropnet/
_ Lấy api key và api secret
_ Code file mainpage.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using BBDropbox.Resources;
using Windows.Security.Authentication.Web;
using DropNet;
using DropNet.Models;
using System.IO.IsolatedStorage;
using System.IO;
using System.Diagnostics;


namespace BBDropbox
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        DropNetClient _client = new DropNetClient("l395hahs18o5uab", "sazu6n8axbfol5f");
        private static string FileName = "accessToken.xml";
        UserLogin userlogin = new UserLogin();
        public MainPage()
        {
            InitializeComponent();
            _client.UseSandbox = false;
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            webAuth.Navigate(new Uri("http://google.com", UriKind.Absolute));
        }
        public void CheckAuthentication(Uri uri)
        {
            if (uri.LocalPath == "/1/oauth/authorize_submit")
            {
                _client.GetAccessTokenAsync((accessToken) =>
                {
                    var item = accessToken;
                    _client.UserLogin = new UserLogin { Token = accessToken.Token, Secret = accessToken.Secret };
                    _client.AccountInfoAsync((success) => {
                        var ed = success;
                    },
                    (error) => {
                 
                    });
                    _client.CreateFolderAsync("/NewFolder1",
                    (metaData) =>
                    {
                        //Do something with metaData
                        var item1 = metaData;
                    },
                    (error) =>
                    {
                        //Do something on error
                    });
                },
                (error) =>
                {
                    MessageBox.Show(error.ToString());
                });
            }
        }
        private void WebBrowser_Navigated(object sender, NavigationEventArgs e)
        {
            CheckAuthentication(e.Uri);
        }
 
        private void SaveAccessTokenToIsolatedStorage(UserLogin user)
        {
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (var stream = new IsolatedStorageFileStream(FileName, FileMode.Create, FileAccess.Write, store))
                {
                    using (StreamWriter writer = new StreamWriter(stream))
                    {
                        writer.WriteLine(user.Token+"|"+user.Secret);
                        Console.WriteLine("You have written to the file.");
                    }
                }
            }
        }

        private UserLogin LoadAccessTokenFromIsolatedStorage()
        {
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (var stream =
                   new IsolatedStorageFileStream(FileName, FileMode.OpenOrCreate, FileAccess.Read, store))
                {
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        String value = reader.ReadToEnd();
                        Debug.WriteLine(value);
                        char[] seperator = new char[1] {'|'};
                        String token = value.Split(seperator).ElementAt(0);
                        String secret = value.Split(seperator).ElementAt(1);
                        userlogin.Token = token;
                        userlogin.Secret = secret;
                        Debug.WriteLine("token ne:" + token + "|" + secret);
                    }
                }
            }
            return null;
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            // Async
            _client.GetTokenAsync((userLogin) =>
            {
                var url = _client.BuildAuthorizeUrl();
                webAuth.Navigate(new Uri(url, UriKind.Absolute));
            },
                (error) =>
                {
                    //Handle error
                });
        }
        private void Button_Click1(object sender, RoutedEventArgs e)
        {
            SaveAccessTokenToIsolatedStorage(new UserLogin { Token = "0rxf8910ixcc7hs7", Secret = "2f49my2nh7fohdy" });
            LoadAccessTokenFromIsolatedStorage();
            /*
            _client.UserLogin = new UserLogin { Token = "0rxf8910ixcc7hs7", Secret = "2f49my2nh7fohdy" };
            _client.AccountInfoAsync((success) =>
            {
                var ed = success;
            },
            (error) =>
            {

            });
       
            _client.DeleteAsync("/unnamed (1).png",
                (response) =>
                {
                    //Do something
                },
                (error) =>
                {
                    //Do something on error
                });
            _client.CreateFolderAsync("/NewFolder1",
            (metaData) =>
            {
                //Do something with metaData
                var item1 = metaData;
            },
            (error) =>
            {
                //Do something on error
            });
           */
        }

    }
}

_ Code file xaml:
<phone:PhoneApplicationPage
    x:Class="BBDropbox.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True">

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!-- LOCALIZATION NOTE:
            To localize the displayed strings copy their values to appropriately named
            keys in the app's neutral language resource file (AppResources.resx) then
            replace the hard-coded text value between the attributes' quotation marks
            with the binding clause whose path points to that string name.

            For example:

                Text="{Binding Path=LocalizedResources.ApplicationTitle, Source={StaticResource LocalizedStrings}}"

            This binding points to the template's string resource named "ApplicationTitle".

            Adding supported languages in the Project Properties tab will create a
            new resx file per language that can carry the translated values of your
            UI strings. The binding in these examples will cause the value of the
            attributes to be drawn from the .resx file that matches the
            CurrentUICulture of the app at run time.
         -->

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <Button Content="checkNotLogin" Click="Button_Click1"></Button>
            <Button Content="checkLogin" Click="Button_Click"></Button>
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <phone:WebBrowser Name="webAuth" Navigated="WebBrowser_Navigated" IsScriptEnabled="True" />
        </Grid>

        <!--Uncomment to see an alignment grid to help ensure your controls are
            aligned on common boundaries.  The image has a top margin of -32px to
            account for the System Tray. Set this to 0 (or remove the margin altogether)
            if the System Tray is hidden.

            Before shipping remove this XAML and the image itself.-->
        <!--<Image Source="/Assets/AlignmentGrid.png" VerticalAlignment="Top" Height="800" Width="480" Margin="0,-32,0,0" Grid.Row="0" Grid.RowSpan="2" IsHitTestVisible="False" />-->
    </Grid>

</phone:PhoneApplicationPage>

Thứ Sáu, 16 tháng 1, 2015

Dùng SQLite trong window phone

Đây là các bài hướng dẫn chi tiết cách làm:
http://stackoverflow.com/questions/23195044/wp8-sqlite-error-the-specified-module-could-not-be-found
http://wp.qmatteoq.com/working-with-sqlite-in-windows-phone-8-a-sqlite-net-version-for-mobile/
http://developer.nokia.com/community/wiki/How_to_use_SQLite_in_Windows_Phone
http://blogs.msdn.com/b/pakistan/archive/2014/04/23/using-sqlite-with-windows-phone-8.aspx

Đặc biệt chú ý muốn có thư viện SQLite for window phone mình phải download về tại http://sqlite.org/download.html . Nơi có thư viện compiled trước cho window phone .
Đây là link thư viện đã thử thành công : http://www.sqlite.org/2013/sqlite-wp80-winrt-3080000.vsix
Đây là thư viện đã dùng thử nhưng nó ko tạo sdk cho mình: https://visualstudiogallery.msdn.microsoft.com/cd120b42-30f4-446e-8287-45387a4f40b7

Thứ Năm, 1 tháng 1, 2015

Save ảnh từ application to IsolatedStorage ,read from IsolatedStorage ,Save to Media library

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;
using System.Windows.Media.Imaging;
using System.IO;
using System.Windows.Resources;
using Microsoft.Xna.Framework.Media;
using Microsoft.Phone.Tasks;

namespace WP7SampleProject40
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }

        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            // Create a filename for JPEG file in isolated storage.
            String tempJPEG = "logo.jpg";

            // Create virtual store and file stream. Check for duplicate tempJPEG files.
            using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (myIsolatedStorage.FileExists(tempJPEG))
                {
                    myIsolatedStorage.DeleteFile(tempJPEG);
                }

                IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(tempJPEG);

                StreamResourceInfo sri = null;
                Uri uri = new Uri(tempJPEG, UriKind.Relative);
                sri = Application.GetResourceStream(uri);

                BitmapImage bitmap = new BitmapImage();
                bitmap.SetSource(sri.Stream);
                WriteableBitmap wb = new WriteableBitmap(bitmap);

                // Encode WriteableBitmap object to a JPEG stream.
                Extensions.SaveJpeg(wb, fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);

                //wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);
                fileStream.Close();
            }
        }

        private void btnRead_Click(object sender, RoutedEventArgs e)
        {
            BitmapImage bi = new BitmapImage();

            using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile("logo.jpg", FileMode.Open, FileAccess.Read))
                {
                    bi.SetSource(fileStream);
                    this.img.Height = bi.PixelHeight;
                    this.img.Width = bi.PixelWidth;
                }
            }
            this.img.Source = bi;
        }

        private void btnMedia_Click(object sender, RoutedEventArgs e)
        {
            using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile("logo.jpg", FileMode.Open, FileAccess.Read))
                {
                    MediaLibrary mediaLibrary = new MediaLibrary();
                    Picture pic = mediaLibrary.SavePicture("SavedLogo.jpg", fileStream);
                    fileStream.Close();
                }
            }

            PhotoChooserTask photoChooserTask = new PhotoChooserTask();
            photoChooserTask.Show();
        }
    }
}

Thứ Tư, 17 tháng 12, 2014

windows-phone-toolkit

http://winphone8dev.blogspot.com/2012/12/longlistmultiselector.html
Ảnh minh họa example : http://blogs.windows.com/buildingapps/2012/11/20/windows-phone-toolkit-overview/
http://channel9.msdn.com/Series/Windows-Phone-8-Development-for-Absolute-Beginners/Part-31-Multiple-Selection-with-the-LongListMultiSelector

Thứ Năm, 4 tháng 12, 2014

Tương tác twitter trong window phone 8

Chúng ta sử dụng thư viện hammock và newtonsoft.Json để parse kết quả :
Example:

<phone:PhoneApplicationPage 
    x:Class="TwitterPost.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True">

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <Grid.RowDefinitions>
            <RowDefinition Height="5*"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        
        <Popup x:Name="StandardPopup"  Width="400" Height="700" IsOpen="False">
            <Grid >
                <phone:WebBrowser Margin="-6,3,0,1" Name="loginBrowserControl" 
                              Navigated="loginBrowserControl_Navigated" Navigating="loginBrowserControl_Navigating" 
                              IsScriptEnabled="True" Width="400" Height="700"/>
            </Grid>
        </Popup>
       

        <Grid x:Name="TweetPanel" Grid.Row="0">
            <Grid.RowDefinitions>
                <RowDefinition Height=".15*"/>
                <RowDefinition Height=".10*"/>
                <RowDefinition Height=".60*"/>
                <RowDefinition Height=".15*"/>
                <RowDefinition Height=".15*"/>
            </Grid.RowDefinitions>

            <TextBlock Grid.Row="0" x:Name="txtUserName" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="26" FontFamily="Segoe WP Bold" Foreground="Red"/>
            <TextBlock Grid.Row="1" Margin="10" VerticalAlignment="Center" HorizontalAlignment="Left" Text="Enter your Tweet" FontSize="24" FontFamily="Segoe WP Bold"/>
            <TextBox Grid.Row="2" x:Name="txtTweetContent" Margin="20,-10,20,100" TextWrapping="Wrap" Text="" FontSize="24" FontFamily="Segoe WP Bold" />
            <Button Grid.Row="3" x:Name="btnPostTweet" Content="Post Tweet" HorizontalAlignment="Center" Click="btnPostTweet_Click"/>
        </Grid>
        <Grid Grid.Row="1" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="1*"/>
                <ColumnDefinition Width="1*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="btnSignIn" Content="Signin" HorizontalAlignment="Center" Click="btnLogin_Click" Grid.Column="0"/>
            <Button x:Name="btnSignOut" Content="Signout" HorizontalAlignment="Center" Click="MenuItemSignOut_Click" Grid.Column="1"/>
        </Grid>
        <!--<Button Grid.Row="3" x:Name="btnPostTweet1" Content="Post Tweet" HorizontalAlignment="Center" Click="btnPostTweet_Click1"/>-->
    </Grid>

</phone:PhoneApplicationPage>


File  class:



using System;
using System.Collections.Generic;
using System.Linq;
using Hammock.Web;
using System.IO;
using Hammock;
using System.Text;
using Hammock.Authentication.OAuth;
using Microsoft.Phone.Controls;
using System.Windows;
using System.Net;
using Newtonsoft.Json.Linq;
namespace TwitterPost
{
    public partial class MainPage : PhoneApplicationPage
    {
        //http://developer.nokia.com/Community/Wiki/Twitter:_OAuth_1.0_Authentication_using_Hammock
        string OAuthTokenKey = string.Empty;
        string tokenSecret = string.Empty;
        string accessToken = string.Empty;
        string accessTokenSecret = string.Empty;
        string userID = string.Empty;
        string userScreenName = string.Empty;
        Uri lasturl ;
        public MainPage()
        {
            InitializeComponent();
            TweetPanel.Visibility = Visibility.Collapsed;
        }
        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            if (isAlreadyLoggedIn())
            {
                userLoggedIn();
            }
            else
            {
                StandardPopup.IsOpen = true;
                var requestTokenQuery = OAuthUtil.GetRequestTokenQuery();
                requestTokenQuery.RequestAsync(AppSettings.RequestTokenUri, null);
                requestTokenQuery.QueryResponse += new EventHandler<WebQueryResponseEventArgs>(requestTokenQuery_QueryResponse);
            }
        }
        private Boolean isAlreadyLoggedIn()
        {
            accessToken = MainUtil.GetKeyValue<string>("AccessToken");
            accessTokenSecret = MainUtil.GetKeyValue<string>("AccessTokenSecret");
            userScreenName = MainUtil.GetKeyValue<string>("ScreenName");

            if (string.IsNullOrEmpty(accessToken) || string.IsNullOrEmpty(accessTokenSecret))
                return false;
            else
                return true;
        }

        private void userLoggedIn()
        {
            Dispatcher.BeginInvoke(() =>
            {
               // var SignInMenuItem = (Microsoft.Phone.Shell.ApplicationBarMenuItem)this.ApplicationBar.MenuItems[0];
               // SignInMenuItem.IsEnabled = false;

               // var SignOutMenuItem = (Microsoft.Phone.Shell.ApplicationBarMenuItem)this.ApplicationBar.MenuItems[1];
                //SignOutMenuItem.IsEnabled = true;
                StandardPopup.IsOpen = false;
                TweetPanel.Visibility = System.Windows.Visibility.Visible;
                txtUserName.Text = "Welcome " + userScreenName;
            });
        }
        private void MenuItemSignOut_Click(object sender, EventArgs e)
        {
            MainUtil.SetKeyValue<string>("AccessToken", string.Empty);
            MainUtil.SetKeyValue<string>("AccessTokenSecret", string.Empty);
            Dispatcher.BeginInvoke(() =>
            {
               // var SignInMenuItem = (Microsoft.Phone.Shell.ApplicationBarMenuItem)this.ApplicationBar.MenuItems[0];
               // SignInMenuItem.IsEnabled = true;

               // var SignOutMenuItem = (Microsoft.Phone.Shell.ApplicationBarMenuItem)this.ApplicationBar.MenuItems[1];
               // SignOutMenuItem.IsEnabled = false;

                TweetPanel.Visibility = System.Windows.Visibility.Collapsed;

                MessageBox.Show("You have been signed out successfully.");
            });
        }
        private void btnPostTweet_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var credentials = new OAuthCredentials
                {
                    Type = OAuthType.ProtectedResource,
                    SignatureMethod = OAuthSignatureMethod.HmacSha1,
                    ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
                    ConsumerKey = AppSettings.consumerKey,
                    ConsumerSecret = AppSettings.consumerKeySecret,
                    Token = this.accessToken,
                    TokenSecret = this.accessTokenSecret,
                    Version = "1.0"
                };

                var restClient = new RestClient
                {
                    Authority = "https://api.twitter.com",
                    HasElevatedPermissions = true
                };

                var restRequest = new RestRequest
                {
                    Credentials = credentials,
                    Path = "/1.1/statuses/update.json",
                    Method = WebMethod.Post
                };

                restRequest.AddParameter("status", txtTweetContent.Text);
                restClient.BeginRequest(restRequest, new RestCallback(PostTweetRequestCallback));
            }
            catch
            {
            }
        }

        public string GetTwitterAvatarUrl(string twitterHandle)
        {
            string avatarUrl = string.Empty;
            var request = new RestRequest
            {
                Credentials = new OAuthCredentials
                {
                    Type = OAuthType.ProtectedResource,
                    SignatureMethod = OAuthSignatureMethod.HmacSha1,
                    ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
                    ConsumerKey = AppSettings.consumerKey,
                    ConsumerSecret = AppSettings.consumerKeySecret,
                    Token = this.accessToken,
                    TokenSecret = this.accessTokenSecret,
                    Version = "1.0"
                }
            };
            request.Path =
                string.Format(
                    "https://api.twitter.com/1.1/users/lookup.json?screen_name={0}&include_entities=0&include_rts=0",
                    twitterHandle);

            request.Method = WebMethod.Get;
            RestClient client = new RestClient();
            try
            {
                client.BeginRequest(request, new RestCallback(RetriveAvatarCallback));
              

            }
            catch (Exception)
            {
                return "default.png";
            }
            return avatarUrl;
        }

        private void RetriveAvatarCallback(RestRequest request, RestResponse response, object obj)
        {
            JArray jArray = JArray.Parse(response.Content);
            var avatarUrl = (string)jArray[0]["profile_image_url_https"];
        }


        public void getFollower(String name)
        {
            var request = new RestRequest
            {
                Credentials = new OAuthCredentials
                {
                    Type = OAuthType.ProtectedResource,
                    SignatureMethod = OAuthSignatureMethod.HmacSha1,
                    ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
                    ConsumerKey = AppSettings.consumerKey,
                    ConsumerSecret = AppSettings.consumerKeySecret,
                    Token = this.accessToken,
                    TokenSecret = this.accessTokenSecret,
                    Version = "1.0"
                }
            };
            request.Path =
                string.Format(
                    "https://api.twitter.com/1.1/followers/list.json?cursor=-1&screen_name={0}&skip_status=true&include_user_entities=false", name);

            request.Method = WebMethod.Get;
            RestClient client = new RestClient();
            try
            {
                client.BeginRequest(request, new RestCallback(RetriveFollowerCallback));
            }
            catch (Exception)
            {

            }
        }
        private void RetriveFollowerCallback(RestRequest request, RestResponse response, object obj)
        {
            JArray jArray = JArray.Parse(response.Content);
            // var avatarUrl = (string)jArray[0]["profile_image_url_https"];
        }
        public void GetTwitterTimelineUrl()
        {
            
            var request = new RestRequest
            {
                Credentials = new OAuthCredentials
                {
                    Type = OAuthType.ProtectedResource,
                    SignatureMethod = OAuthSignatureMethod.HmacSha1,
                    ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
                    ConsumerKey = AppSettings.consumerKey,
                    ConsumerSecret = AppSettings.consumerKeySecret,
                    Token = this.accessToken,
                    TokenSecret = this.accessTokenSecret,
                    Version = "1.0"
                }
            };
            request.Path =
                string.Format(
                    "https://api.twitter.com/1.1/statuses/home_timeline.json");

            request.Method = WebMethod.Get;
            RestClient client = new RestClient();
            try
            {
                client.BeginRequest(request, new RestCallback(RetriveTimelineCallback));
            }
            catch (Exception)
            {
          
            }
          
        }
         private void RetriveTimelineCallback(RestRequest request, RestResponse response, object obj)
        {
            JArray jArray = JArray.Parse(response.Content);
           // var avatarUrl = (string)jArray[0]["profile_image_url_https"];
        }

        private void PostTweetRequestCallback(RestRequest request, RestResponse response, object obj)
        {
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    MessageBox.Show("TWEET_POSTED_SUCCESSFULLY");
                }
                else if (response.StatusCode == HttpStatusCode.Forbidden)
                {
                    MessageBox.Show("TWEET_POST_ERR_UPDATE_LIMIT");
                }
                else
                {
                    MessageBox.Show("WEET_POST_ERR_FAILED");
                }
                txtTweetContent.Text = "";
            });
            //var requestTokenQuery = OAuthUtil.GetRequestTokenQuery();
            //requestTokenQuery.RequestAsync(AppSettings.RequestTokenUri, null);
            //requestTokenQuery.QueryResponse += new EventHandler<WebQueryResponseEventArgs>(requestTokenQuery_QueryResponse);
        }

        void requestTokenQuery_QueryResponse(object sender, WebQueryResponseEventArgs e)
        {
            try
            {
                StreamReader reader = new StreamReader(e.Response);
                string strResponse = reader.ReadToEnd();
                var parameters = MainUtil.GetQueryParameters(strResponse);
                OAuthTokenKey = parameters["oauth_token"];
                tokenSecret = parameters["oauth_token_secret"];
                var authorizeUrl = AppSettings.AuthorizeUri + "?oauth_token=" + OAuthTokenKey;

                Dispatcher.BeginInvoke(() =>
                {
                    StandardPopup.IsOpen = true;
                    this.loginBrowserControl.Navigate(new Uri(authorizeUrl, UriKind.RelativeOrAbsolute));
                });
            }
            catch (Exception ex)
            {
                Dispatcher.BeginInvoke(() =>
                {
                    MessageBox.Show(ex.Message);
                });
            }
        }


        private void loginBrowserControl_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
        {
            lasturl = e.Uri;
            System.Diagnostics.Debug.WriteLine("loginBrowserControl_Navigated");
            //StandardPopup.IsOpen = false;
           // this.loginBrowserControl.Navigated -= loginBrowserControl_Navigated;
        }

        private void loginBrowserControl_Navigating(object sender, NavigatingEventArgs e)
        {
            System.Diagnostics.Debug.WriteLine("loginBrowserControl_Navigating");
            try
            {
                if (e.Uri.ToString().StartsWith(AppSettings.CallbackUri))
                {
                    var AuthorizeResult = MainUtil.GetQueryParameters(e.Uri.ToString());
                    var VerifyPin = AuthorizeResult["oauth_verifier"];
                    var AccessTokenQuery = OAuthUtil.GetAccessTokenQuery(OAuthTokenKey, tokenSecret, VerifyPin);

                    AccessTokenQuery.QueryResponse += new EventHandler<WebQueryResponseEventArgs>(AccessTokenQuery_QueryResponse);
                    AccessTokenQuery.RequestAsync(AppSettings.AccessTokenUri, null);
                }
            }
            catch
            {
            }
        }

        void AccessTokenQuery_QueryResponse(object sender, WebQueryResponseEventArgs e)
        {
            try
            {
                StreamReader reader = new StreamReader(e.Response);
                string strResponse = reader.ReadToEnd();
                var parameters = MainUtil.GetQueryParameters(strResponse);
                accessToken = parameters["oauth_token"];
                accessTokenSecret = parameters["oauth_token_secret"];
                userID = parameters["user_id"];
                userScreenName = parameters["screen_name"];

                MainUtil.SetKeyValue<string>("AccessToken", accessToken);
                MainUtil.SetKeyValue<string>("AccessTokenSecret", accessTokenSecret);
                MainUtil.SetKeyValue<string>("ScreenName", userScreenName);
                //GetTwitterAvatarUrl(userScreenName);
                //GetTwitterTimelineUrl();
                getFollower(userScreenName);

                userLoggedIn();
            }
            catch (Exception ex)
            {
                Dispatcher.BeginInvoke(() =>
                {
                    MessageBox.Show(ex.Message);
                });
            }
        }

        private void btnPostTweet_Click1(object sender, RoutedEventArgs e)
        {
           
            //this.loginBrowserControl.Visibility = Visibility.Collapsed;
            //this.loginBrowserControl.Navigate(lasturl);
            //this.loginBrowserControl.InvokeScript("eval", "history.go(-1)");
            //var requestTokenQuery = OAuthUtil.GetRequestTokenQuery();
            //requestTokenQuery.RequestAsync(AppSettings.RequestTokenUri, null);
            //requestTokenQuery.QueryResponse += new EventHandler<WebQueryResponseEventArgs>(requestTokenQuery_QueryResponse);
        }
    }
}

Bonus thêm các link quan trọng:
  Lấy thông tin timeline :https://api.twitter.com/1.1/statuses/home_timeline.json
  Lấy thông tin những người follower mình :https://api.twitter.com/1.1/followers/list.json?cursor=-1&screen_name={0}&skip_status=true&include_user_entities=false
  Lấy avatar của người có tên là : https://api.twitter.com/1.1/users/lookup.json?screen_name={0}&include_entities=0&include_rts=0



Reference:
http://bsubramanyamraju.blogspot.in/2013/11/latest-twitter-integration-in-windows.html
https://code.msdn.microsoft.com/windowsapps/Latest-Twitter-integration-a42e8bb6
http://www.rhizohm.net/irhetoric/post/2013/05/01/Getting-Twitter-Avatar-Via-C-With-11-API.aspx

Example hay nhưng chưa thử :https://code.msdn.microsoft.com/windowsapps/twitter-sample-using-0dfcce61