The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Psychlist1972 (177) [Avatar] Offline
#1
So, of course Twitter decided to turn off their search API as of June 11. This breaks the chapter 1 twitter example.

Here's an email I got from a reader:
I just started reading through your Windows Store App book. Just wanted to warn you that Twitter turned off the API you use in the HelloWorld example of Chapter 1. The response text directs you to a page that says it will be shut down on 11June2013, after which the new API must be used. The new API is a lot different. It's JSON only and requires authentication via OAuth.

I'll need to come up with another example, as tackling OAuth in a Hello World class example is not appropriate.

Pete
PKRoma (1) [Avatar] Offline
#2
Re: Twitter example in chapter 1
For what it's worth, here's the diffs to change the example to use Joe Mayo's LINQ to Twitter service (via NuGet). Using it this way you must insert your own OAuth keys and tokens though (get them from dev.twitter.com)...

$ git diff
diff --git a/HelloWorld/HelloWorld.csproj b/HelloWorld/HelloWorld.csproj
index 12bf7bc..cb333a0 100644
--- a/HelloWorld/HelloWorld.csproj
+++ b/HelloWorld/HelloWorld.csproj
@@ -117,6 +117,7 @@
<SubType>Designer</SubType>
</AppxManifest>
<None Include="HelloWorld_TemporaryKey.pfx" />
+ <None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="AssetsLogo.png" />
@@ -138,6 +139,11 @@
<SubType>Designer</SubType>
</Page>
</ItemGroup>
+ <ItemGroup>
+ <Reference Include="LinqToTwitterRT">
+ <HintPath>..packagesLinqToTwitter.2.1.8libwinrt45LinqToTwitterRT.dll</HintPath>
+ </Reference>
+ </ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '11.0' ">
<VisualStudioVersion>11.0</VisualStudioVersion>
</PropertyGroup>
diff --git a/HelloWorld/MainPage.xaml.cs b/HelloWorld/MainPage.xaml.cs
index 41d8dc1..0f1ac2b 100644
--- a/HelloWorld/MainPage.xaml.cs
+++ b/HelloWorld/MainPage.xaml.cs
@@ -1,3 +1,4 @@
+using LinqToTwitter;
using System;
using System.Collections.ObjectModel;
using System.Diagnostics;
@@ -37,25 +38,38 @@ namespace HelloWorld

private async void LoadTweets()
{
- Uri uri = new Uri("http://search.twitter.com/search.atom?q=win8+OR+windows8");
+ string fileName = "Linq2TwitterCredentials.txt";

- var client = new HttpClient();
- var response = await client.GetAsync(uri);
+ var auth = new WinRtAuthorizer
+ {
+ Credentials = new LocalDataCredentials(fileName)
+ {
+ ConsumerKey = "",
+ ConsumerSecret = "",
+ OAuthToken = "",
+ AccessToken = "" // Access token for user (secret)
+ },
+ UseCompression = true,
+ Callback = new Uri("http://callback-url-defined-in-twitter.com/")
+ };

- string content = await response.Content.ReadAsStringAsync();
+ if (auth == null || !auth.IsAuthorized)
+ {
+ await auth.AuthorizeAsync();
+ }

- Debug.WriteLine(content);
+ var twitterCtx = new TwitterContext(auth);

- var doc = XDocument.Parse(content);
- XNamespace ns = "http://www.w3.org/2005/Atom";
+ var searchResponse = (from search in twitterCtx.Search
+ where search.Type == SearchType.Search && search.Query == "win8+OR+windows8"
+ select search)
+ .SingleOrDefault();

- var items = from item in doc.Descendants(ns + "entry")
- select new Tweet()
+ var items = from item in searchResponse.Statuses
+ select new Tweet
{
- Message = item.Element(ns + "title").Value,
- Image = (from XElement xe in item.Descendants(ns + "link")
- where xe.Attribute("type").Value == "image/png"
- select xe.Attribute("href").Value).First()
+ Message = item.Text,
+ Image = item.User.ProfileImageUrl
};

_tweets.Clear();
diff --git a/HelloWorld/packages.config b/HelloWorld/packages.config
new file mode 100644
index 0000000..7525968
--- /dev/null
+++ b/HelloWorld/packages.config
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="LinqToTwitter" version="2.1.8" targetFramework="win" />
+</packages>
No newline at end of file
diff --git a/packages/repositories.config b/packages/repositories.config
new file mode 100644
index 0000000..f882a0e
--- /dev/null
+++ b/packages/repositories.config
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<repositories>
+ <repository path="..HelloWorldpackages.config" />
+</repositories>
No newline at end of file

Peter@GAISMA /i/Users/Peter/Src/WindowsStoreAppDevelopment/HelloWorld (master)
$