http://code.google.com/p/google-reader-api/w/list
特に難しい認証の部分はこちらの説明に
http://www.yoheim.net/blog.php?q=20120608
C#で書いてみました。こんな感じです。
using System; using System.IO; using System.Net; using System.Text; namespace GoogleReaderDemo { internal class Program { private static void Main(string[] args) { var sw = new StreamWriter("Feed.txt"); Console.SetOut(sw); // Setup Request, uri, method, contenttype, contentlength and write the post data to requeststream. var res = (HttpWebRequest) WebRequest.Create(new Uri(@"https://www.google.com/accounts/ClientLogin")); res.Method = "POST"; res.ContentType = "application/x-www-form-urlencoded"; const string postData = "Email=yourname@gmail.com&Passwd=yourpassword&service=reader"; byte[] bytes = Encoding.ASCII.GetBytes(postData); res.ContentLength = bytes.Length; string rspBody = ""; using (Stream s = res.GetRequestStream()) { s.Write(bytes, 0, bytes.Length); WebResponse rsp = res.GetResponse(); var streamReader = new StreamReader(rsp.GetResponseStream()); streamReader.ReadLine(); streamReader.ReadLine(); rspBody = streamReader.ReadToEnd(); } // Request RSS with a name:value pair: Authorization:GoogleLogin AUTH=..." res = (HttpWebRequest) WebRequest.Create(new Uri(@"http://www.google.com/reader/atom/")); res.Headers.Add("Authorization", "GoogleLogin " + rspBody); rspBody = new StreamReader(res.GetResponse().GetResponseStream()).ReadToEnd(); Console.Write(rspBody); Console.ReadLine(); } } }
ATOM形式で返してくるので、どっかのParserがあればいいですね・・・自分書くのが面倒で・・・
Nugetで探したら、すぐ出てきました。
http://qdfeed.codeplex.com/
これでいけそう!
やってみました。
using System; using System.IO; using System.Net; using System.Text; using QDFeedParser; namespace GoogleReaderDemo { internal class Program { private static void Main(string[] args) { // Setup Request, uri, method, contenttype, contentlength and write the post data to requeststream. var res = (HttpWebRequest) WebRequest.Create(new Uri(@"https://www.google.com/accounts/ClientLogin")); res.Method = "POST"; res.ContentType = "application/x-www-form-urlencoded"; const string postData = "Email=youremail@gmail.com&Passwd=yourpassword&service=reader"; byte[] bytes = Encoding.ASCII.GetBytes(postData); res.ContentLength = bytes.Length; string rspBody = ""; using (Stream s = res.GetRequestStream()) { s.Write(bytes, 0, bytes.Length); WebResponse rsp = res.GetResponse(); var streamReader = new StreamReader(rsp.GetResponseStream()); streamReader.ReadLine(); streamReader.ReadLine(); rspBody = streamReader.ReadToEnd(); } // Request RSS with a name:value pair: Authorization:GoogleLogin AUTH=..." res = (HttpWebRequest) WebRequest.Create(new Uri(@"http://www.google.com/reader/atom/")); res.Headers.Add("Authorization", "GoogleLogin " + rspBody); rspBody = new StreamReader(res.GetResponse().GetResponseStream()).ReadToEnd(); File.WriteAllText(@"C:\Users\Z\Desktop\Feed.txt", rspBody); IFeedFactory factory = new FileSystemFeedFactory(); IFeed feed = factory.CreateFeed(new Uri(@"C:\Users\Z\Desktop\Feed.txt")); foreach (BaseFeedItem i in feed.Items) { Console.WriteLine("_____________________________________________________"); Console.WriteLine("Title : " + i.Title + Environment.NewLine); Console.WriteLine("Link : " + i.Link + Environment.NewLine); Console.WriteLine("Date : " + i.DatePublished); } Console.ReadLine(); } } }
0 件のコメント:
コメントを投稿