Authenticating with ClientLogin and using the Google Reader API in Android

房东的猫 提交于 2019-12-06 13:42:58
ptdev

If you're using ClientLogin you will probably need only 2 kinds of tokens to do what you need with the unnoficial Google Reader API:

  • Authentication Token - This is the main authentication token, and you'll need to send this in the header of every GET/POST request to the API, otherwise you'll get an error (not the one you're having, though). You can do a POST to this url for this (I have a full code example ahead): https://www.google.com/accounts/ClientLogin
  • Edit Token - This is the edit token, and you'll need to send this as a form parameter of POST request to any edit APIs (like the http://www.google.com/reader/api/0/edit you've mentioned). You can do a GET to this url for this (I have a code example ahead): http://www.google.com/reader/api/0/token

Getting to the 404 error you're reporting, it must be that you have a typo in your url. Copy my url and try it out. Double check it, side by side. Here is the Java code I've used for this - you can try it out also:

    private static final String _AUTHPARAMS = "GoogleLogin auth=";
    private static final String _GOOGLE_LOGIN_URL = "https://www.google.com/accounts/ClientLogin";
    private static final String _READER_BASE_URL = "http://www.google.com/reader/";
    private static final String _API_URL = _READER_BASE_URL + "api/0/";
    private static final String _TOKEN_URL = _API_URL + "token";
    private static final String _USER_INFO_URL = _API_URL + "user-info";
    private static final String _USER_LABEL = "user/-/label/";
    private static final String _TAG_LIST_URL = _API_URL + "tag/list";
    private static final String _EDIT_TAG_URL = _API_URL + "tag/edit";
    private static final String _RENAME_TAG_URL = _API_URL + "rename-tag";
    private static final String _DISABLE_TAG_URL = _API_URL + "disable-tag";
    private static final String _SUBSCRIPTION_URL = _API_URL
    + "subscription/edit";
    private static final String _SUBSCRIPTION_LIST_URL = _API_URL
    + "subscription/list";

    public static String getGoogleAuthKey() throws IOException {

        String _USERNAME = "USER_EMAIL@gmail.com";
        String _PASSWORD = "USER_PASSWORD";

        Document doc = Jsoup
        .connect(_GOOGLE_LOGIN_URL)
        .data("accountType", "GOOGLE", "Email", _USERNAME, "Passwd",
                _PASSWORD, "service", "reader", "source",
                "[YOUR_APP_ID_GOES_HERE].apps.googleusercontent.com")
        .userAgent("[YOUR_APP_ID_GOES_HERE].apps.googleusercontent.com")
        .timeout(4000).post();

// RETRIEVES THE RESPONSE TEXT inc SID and AUTH. We only want the AUTH
// key.
String _AUTHKEY = doc
        .body()
        .text()
        .substring(doc.body().text().indexOf("Auth="),
                doc.body().text().length());
_AUTHKEY = _AUTHKEY.replace("Auth=", "");
return _AUTHKEY;

}

You can see a code example for getting the edit token and doing an edit in my answer to this other question.

See my answer to this one if you want documentation (unofficial but well structured) - there is no official doc...

The code is based on http://www.chrisdadswell.co.uk/android-coding-example-authenticating-clientlogin-google-reader-api/

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