2010-12-09 60 views
2

有誰知道是否有Google Reader服務調用,用戶可以獲取所有屬於某個標籤/類別的所有訂閱源的名稱/ URI嗎?謝謝!Google Reader API - 獲取訂閱源

+0

你想讓它基於登錄返回它們嗎?或一般用於飼料發現? – smilbandit 2010-12-10 16:50:27

回答

2

您可以使用以下代碼的變種來訪問Google Reader系統。您需要爲每個請求發送標題(「授權」,「auth =」+ myauthvar)。爲了編輯項目,你需要下面我演示的令牌。一旦你有了驗證碼,你可以發佈(帶有該頭文件)到http://www.google.com/reader/api/0/subscription/list?output=xml,以便返回完整的訂閱列表。

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Net; 
using System.IO; 

namespace ConsoleApplication2 
{ 
    class Program 
    { 

     static void Main(string[] args) 
     { 
      getAuth(); 

      Console.ReadLine(); 
     } 

     public static void getAuth() 
     { 

      //put in the username and password 
      string postData = "[email protected]&Passwd=YOURPASSWORD&service=reader&source=some-uniqueapp-v1"; 

      WebRequest authReq = WebRequest.Create("https://www.google.com/accounts/ClientLogin"); 
      authReq.ContentType = "application/x-www-form-urlencoded"; 
      authReq.Method = "POST"; 

      byte[] bytes = Encoding.ASCII.GetBytes(postData); 
      authReq.ContentLength = bytes.Length; 
      Stream os = authReq.GetRequestStream(); 
      os.Write(bytes, 0, bytes.Length); 

      WebResponse resp = authReq.GetResponse(); 

      StreamReader sr = new StreamReader(resp.GetResponseStream()); 

      string responseContent = sr.ReadToEnd().Trim(); 

      string[] responseSpilt = responseContent.Split('='); 

      string authticket = responseSpilt[3]; 

      Console.WriteLine("Auth = " + authticket); 

      sr.Close(); 

      getToken(authticket); 

     } 

     public static void getToken(string auth) 
     { 

      WebRequest tokenReq = WebRequest.Create("https://www.google.com/reader/api/0/token"); 
      tokenReq.ContentType = "application/x-www-form-urlendcoded"; 
      tokenReq.Method = "GET"; 

      tokenReq.Headers.Add("Authorization", "GoogleLogin auth=" + auth); 

      WebResponse response = tokenReq.GetResponse(); 
      if (response == null) return; 

      StreamReader sr = new StreamReader(response.GetResponseStream()); 
      string respContent = sr.ReadToEnd().Trim(); 

      string[] respSplit = respContent.Split('/'); 

      string token = respSplit[2]; 

      Console.WriteLine(" "); 

      Console.WriteLine("Token = " + token); 

      sr.Close(); 

     } 
    } 
} 
相關問題