【问题标题】:Get latest tweet using Tweetsharp on Windows Phone 7在 Windows Phone 7 上使用 Tweetsharp 获取最新推文
【发布时间】:2013-06-18 13:02:42
【问题描述】:

我只想使用 Tweetsharp 将最新推文发送到我的 Windows Phone 应用程序。以下是我所做的:

  1. 使用 Nuget 包管理器安装 Tweetsharp。
  2. 将我的应用注册到 Twitter 开发者网站。
  3. 获取消费者密钥、消费者秘密、令牌和令牌秘密。
  4. 使用这 4 个键初始化 TwitterService。

那么,接下来呢?我上面的步骤有什么错误吗?我真的很困惑。

【问题讨论】:

  • 显示一些代码将帮助您获得答案。
  • 如果您关心的是获取推文,只需使用"http://search.twitter.com/search.json?q=from: + ID + &since:2012-01-01 即可

标签: c# windows-phone-7 windows-phone-7.1 tweetsharp


【解决方案1】:

关于 tweetsharp 的文档可在 wiki 上找到。

最好的方法是statuses/user_timeline:

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

您已具备所有先决条件。让我们编码吧!

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

就是这样!

【讨论】:

  • 不错的答案,但现在我收到错误(215 Bad Authantecation Error)作为响应...这是 Api v1 已退休并且现在 api v1.1 可用的问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-08-09
  • 2015-09-13
  • 2016-03-15
  • 1970-01-01
  • 2014-04-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多