在Windows Phone 7上使用Tweetsharp获取最新的Tweet [英] Get latest tweet using Tweetsharp on Windows Phone 7

查看:88
本文介绍了在Windows Phone 7上使用Tweetsharp获取最新的Tweet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想使用Tweetsharp向我的Windows Phone应用程序获取最新的推文.以下是我所做的:

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

  1. 使用Nuget软件包管理器安装Tweetsharp.
  2. 将我的应用程序注册到Twitter开发人员站点.
  3. 获取消费者密钥,消费者密钥,令牌和令牌密钥.
  4. 使用那四个键初始化TwitterService.

然后,下一步是什么?我上面的步骤有什么错误吗?我真的很困惑.

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

推荐答案

tweetsharp的文档可在 wiki .

The documentation for tweetsharp is available on the wiki.

最好的方法是 statuses/user_timeline :

The best method is statuses/user_timeline :

返回用户发布的最新推文的集合 由screen_name或user_id参数指示

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 !

一块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>

和一段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; });
            }
        });
}

仅此而已!

这篇关于在Windows Phone 7上使用Tweetsharp获取最新的Tweet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆