我只想使用Tweetsharp向我的Windows Phone应用程序发送最新推文。以下就是我所做的:
然后,下一步是什么?我上面的步骤有什么错误吗?我真的很困惑。
答案 0 :(得分: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; });
}
});
}
就是这样!