如何标记使用Google Reader API读取的项目? [英] How to mark items read with google reader API?

查看:80
本文介绍了如何标记使用Google Reader API读取的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在为Google Reader的客户端工作.一切工作正常,除了我无法编辑条目以添加诸如已加星标"和已读"之类的标签. code.google.com/p/pyrfeed/wiki/GoogleReaderAPI和www.niallkennedy.com/blog/2005/12/google-reader-api.html上的说明似乎已过时.更奇怪的是,我一直在检查google本身使用的POST数据,并试图准确地复制它,但仍然无法正常工作.例如,我最接近的是 http://www.google带有POST数据的.com/reader/api/0/edit-tag a =/user/-/state/com.google/starred& async = true& s = [feed]& i = [item] & T = [令牌]

I've been working on a client for google reader. Everything works fine, except that I can't edit entries to add tags such as "starred" and "read." The instructions at code.google.com/p/pyrfeed/wiki/GoogleReaderAPI and www.niallkennedy.com/blog/2005/12/google-reader-api.html seem to be outdated. What's more odd is that I've been inspecting the POST data that google itself uses and attempting to replicate it exactly, but I still can't get it to work. The closest I've come is, for example, http://www.google.com/reader/api/0/edit-tag with POST data a=/user/-/state/com.google/starred&async=true&s=[feed]&i=[item]&T=[token]

这似乎正是Google本身所做的,但我总是找回无效的流名称".有什么建议吗?

This seems to be exactly what google itself does, but I lways get back "Invalid Stream Name." Any advice?

推荐答案

我没有确定的答案,但是我在使用API​​ api/0/edit-tag时遇到了一些麻烦并设法将其获取工作.

I don't have a definitive answer for you, but I was also having some trouble with the API api/0/edit-tag and managed to get them working.

我已经在使用API​​的其他部分,而没有遇到任何麻烦(api/0/stream/items/ids,api/0/unread-count),但是这一过程并不那么容易.

I was already using other parts of the API without any trouble (api/0/stream/items/ids, api/0/unread-count), but this one was not working as easily.

过了一会儿,我首先检查了他们的Web前端发送给Google Reader的请求(使用Chrome开发工具),并制作了一个硬编码示例(您可以使用此代码,而只需更改ID和流为自己拥有-请注意它们具有所有必需的前缀:feed/用于流,以及tag:google.com,2005:reader/item/用于id).

After a while, I started over by inspecting the requests sent to Google Reader by their web frontend (using Chrome dev tools), and made an hardcoded example (you can use this code and you just need to change the ids and stream for you own - just be careful that they have all the needed prefixes: feed/ for stream, and tag:google.com,2005:reader/item/ for id).

        String authToken = getGoogleAuthKey();
        // I use Jsoup for the requests, but you can use anything you
        // like - for jsoup you usually just need to include a jar
        // into your java project
    Document doc = Jsoup.connect("http://www.google.com/reader/api/0/edit-tag")
        .header("Authorization", _AUTHPARAMS + authToken)
        .data(
                    // you don't need the userid, the '-' will suffice
                "a", "user/-/state/com.google/read",
                "async", "true",
                "s", "feed/http://www.gizmodo.com/index.xml",
                "i", "tag:google.com,2005:reader/item/1a68fb395bcb6947",
                "T", "//wF1kyvFPIe6JiyITNnMWdA"
        )
        // I also send my API key, but I don't think this is mandatory
        .userAgent("[YOUR_APP_ID_GOES_HERE].apps.googleusercontent.com")
        .timeout(10000)
        // don't forget the post! (using get() will not work)
        .**post()**;

这是我的最终代码,用于将流中的特定项目标记为已读(translateToItemAtomId方法用于将api/0/stream/items/ids返回的长整数id转换为该对象接受的atom xml id API):

Here is my final code for marking a specific item from a stream as read (the translateToItemAtomId method is used for converting the long integer ids as returned by api/0/stream/items/ids into the atom xml ids accepted by this API):

        String authToken = getGoogleAuthKey();
    Document doc = Jsoup.connect("http://www.google.com/reader/api/0/edit-tag")
        .header("Authorization", _AUTHPARAMS + authToken)
        .data(
                "a", "user/-/state/com.google/read",
                "async", "true",
                "s", stream,
                "i", translateToItemAtomId(itemId),
                "T", getGoogleToken(authToken)
        )
        .userAgent("[YOUR_APP_ID_GOES_HERE].apps.googleusercontent.com")
        .timeout(10000).post();

您可能需要一些额外的代码(基于

Some extra code you may need (based on http://www.chrisdadswell.co.uk/android-coding-example-authenticating-clientlogin-google-reader-api/):

    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;
}

// generates a token for edition, needed for edit-tag
public static String getGoogleToken(String authToken) throws IOException {
    Document doc = Jsoup.connect(_TOKEN_URL)
            .header("Authorization", _AUTHPARAMS + getGoogleAuthKey())
            .userAgent("[YOUR_APP_ID_GOES_HERE].apps.googleusercontent.com")
            .timeout(10000).get();

    // RETRIEVES THE RESPONSE TOKEN
    String _TOKEN = doc.body().text();
    return _TOKEN;
}

希望这会有所帮助!

这篇关于如何标记使用Google Reader API读取的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆