Google Reader API - Getting Feeds

我怕爱的太早我们不能终老 提交于 2020-01-29 04:12:07

问题


Does anyone know if there is a Google Reader service call that a user can make to get the name/uri of all feeds that fall under a certain label/category? Thanks!


回答1:


You can use a variation of the code below to get access to the Google Reader system. You need to send the header ("Authorization", "auth=" +myauthvar) with each request. In order to edit items you will need the token which I also demo below. Once you have the auth id you can post (with that header intact) to http://www.google.com/reader/api/0/subscription/list?output=xml in order to return the full subscription listing.

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=YOURUSERNAME@gmail.com&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();

        }
    }
}


来源:https://stackoverflow.com/questions/4400893/google-reader-api-getting-feeds

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!