Get latest tweet using Tweetsharp on Windows Phone 7

瘦欲@ 提交于 2019-12-02 09:40:59

问题


I only want to get a latest tweet to my Windows Phone Apps using Tweetsharp. below is what I have done:

  1. Installing Tweetsharp using Nuget Package Manager.
  2. Registering my apps to Twitter Developer Site.
  3. Get Consumer key, Consumer Secret, token, and token secret.
  4. Initializing TwitterService using that 4 keys.

Then, what is next? are there any mistakes of my steps above? I am really confused.


回答1:


The documentation for tweetsharp is available on the wiki.

The best method is statuses/user_timeline :

Returns a collection of the most recent Tweets posted by the user indicated by the screen_name or user_id parameters

You have all the prerequisites. Let's code !

A piece of Xaml

<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1">
    <Grid.Resources>
        <DataTemplate x:Key="tweetList">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <TextBlock Grid.Row="0" TextWrapping="Wrap"  Text="{Binding Text}"/>
                <TextBlock Grid.Row="1" HorizontalAlignment="Right"  Text="{Binding CreatedDate}" FontSize="12" FontStyle="Italic"/>
            </Grid>
        </DataTemplate>
    </Grid.Resources>
    <TextBlock  Text="Tweet List" FontSize="26" HorizontalAlignment="Center" Margin="10" />
    <ListBox 
       Height="650"               
        Margin="0,20,0,0"
      ScrollViewer.VerticalScrollBarVisibility="Visible"
      ItemTemplate="{StaticResource tweetList}"
      x:Name="tweetList">
    </ListBox>
</Grid>

and a piece of C#

// Constructor
public MainPage()
{
    InitializeComponent();
    this.Loaded += new RoutedEventHandler(MainPage_Loaded);
}

void MainPage_Loaded(object sender, RoutedEventArgs e)
{
    var service = new TwitterService("yourconsumerKey", "yourconsumerSecret");
    service.AuthenticateWith("youraccessToken", "youraccessTokenSecret");

    service.ListTweetsOnUserTimeline(new ListTweetsOnUserTimelineOptions() { ScreenName = "SCREENNAME" }, (ts, rep) =>
        {
            if (rep.StatusCode == HttpStatusCode.OK)
            {
                //bind
                this.Dispatcher.BeginInvoke(() => { tweetList.ItemsSource = ts; });
            }
        });
}

that's all !



来源:https://stackoverflow.com/questions/17169571/get-latest-tweet-using-tweetsharp-on-windows-phone-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!