如何使用 google reader API 标记已读项目?

发布于 2024-08-05 03:04:48 字数 506 浏览 6 评论 0原文

我一直在为谷歌阅读器开发一个客户端。一切工作正常,除了我无法编辑条目以添加“加星标”和“已读”等标签。 code.google.com/p/pyrfeed/wiki/GoogleReaderAPI 和 www.niallkennedy.com/blog/2005/12/google-reader-api.html 上的说明似乎已过时。更奇怪的是,我一直在检查谷歌本身使用的 POST 数据并尝试准确复制它,但我仍然无法让它工作。例如,我最接近的是 http://www.google .com/reader/api/0/edit-tag,包含 POST 数据 a=/user/-/state/com.google/starred&async=true&s=[feed]&i=[item] &T=[token]

这似乎正是谷歌本身所做的,但我总是得到“无效的流名称”。有什么建议吗?

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]

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

中二柚 2024-08-12 03:04:48

我没有给你一个明确的答案,但我在 API api/0/edit-tag 方面也遇到了一些麻烦,并设法让它们正常工作。

我已经在使用 API 的其他部分,没有任何问题(api/0/stream/items/ids、api/0/unread-count),但是这个部分工作起来并不那么容易。

一段时间后,我重新开始检查他们的网络前端(使用 Chrome 开发工具)发送到 Google Reader 的请求,并制作了一个硬编码示例(您可以使用此代码,只需更改您自己的 id 和流) - 请注意它们具有所有必需的前缀:feed/(用于流)和 tag:google.com,2005:reader/item/(用于 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 转换为该 API 接受的原子 xml id):

        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();

您可能需要一些额外的代码(基于 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 = "[email protected]";
    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;
}

希望这有帮助!

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.

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.

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()**;

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 = "[email protected]";
    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;
}

Hope this helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文