Java 谷歌阅读器API认证

Java 谷歌阅读器API认证,java,authentication,google-reader,Java,Authentication,Google Reader,我正在尝试使用以下代码段在google api服务上进行身份验证: RestTemplate restTemplate = new RestTemplate(); List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>> restTemplate.getMessageConverters()); converters.add(new Pr

我正在尝试使用以下代码段在google api服务上进行身份验证:

RestTemplate restTemplate = new RestTemplate();
List<HttpMessageConverter<?>> converters =
   new ArrayList<HttpMessageConverter<?>> restTemplate.getMessageConverters());
converters.add(new PropertiesHttpMessageConverter());
restTemplate.setMessageConverters(converters);

Properties result = preparePostTo(AUTHENTICATION_URL)
                .using(restTemplate)
                .expecting(Properties.class)
                .withParam("accountType", "HOSTED_OR_GOOGLE")
                .withParam("Email", email)
                .withParam("Passwd", password)
                .withParam("service", "reader")
                .withParam("source", "google-like-filter")
                .execute();
String token = (String) result.get("Auth");
但当我使用这个url获取内容时,我得到了401客户端错误异常。可能是什么

根据这个问题,一切都应该是好的


我只需将url粘贴到浏览器中即可获取内容。

尝试使用OAuth进行谷歌阅读器身份验证/授权。您只需使用OAuth库并向Google注册应用程序,即可获得OAuth用户密钥/密码


你可以使用或。

嘿,不知道这是否对你有帮助,或者你是否还在乎,但我最终进入了Google Reader,并使用了我编写的以下ConsoleApp代码(请注意,这是C语言,但应该很容易翻译成Java)

Try,我开发的一个非官方的Google Reader Java客户端。
URL url = new URL(LIKERS_URL + "?i=" + id);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.addRequestProperty("Authorization", "GoogleLogin Auth=" + token);
return url;
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();

        }
    }
}