Feedly API& JSON

时间:2017-10-16 09:40:32

标签: python json api feedly

我正在尝试访问Feedly API以自动收集和分享文章到Facebook群组。到目前为止,我甚至无法弄清楚如何使用此处的Feedly API包装器:https://github.com/zgw21cn/FeedlyClient

from feedlyclient import FeedlyClient

# Feedly

feedaccess = "removed"
myfeedId = "removed"

con = FeedlyClient()
con.get_feed_content(feedaccess,myfeedId,False,10000)
parsed = json.loads(con)
print json.dumps(parsed)

终端

PS D:\Python Projects\Python 2\fbauto> & python "d:/Python Projects/Python 2/fbauto/feedlytest.py"
Traceback (most recent call last):
  File "d:/Python Projects/Python 2/fbauto/feedlytest.py", line 8, in <module>
    con = FeedlyClient.get_feed_content(feedaccess,myfeedId,False,10000)
TypeError: unbound method get_feed_content() must be called with FeedlyClient instance as first argument (got str instance instead)
PS D:\Python Projects\Python 2\fbauto> & python "d:/Python Projects/Python 2/fbauto/feedlytest.py"
Traceback (most recent call last):
  File "d:/Python Projects/Python 2/fbauto/feedlytest.py", line 9, in <module>
    con.get_feed_content(feedaccess,myfeedId,False,10000)
  File "d:\Python Projects\Python 2\fbauto\feedlyclient.py", line 75, in get_feed_content
    return res.json()
  File "C:\Python27\lib\site-packages\requests\models.py", line 892, in json
    return complexjson.loads(self.text, **kwargs)
  File "C:\Python27\lib\json\__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "C:\Python27\lib\json\decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Python27\lib\json\decoder.py", line 382, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

请帮忙。

第二次尝试

import json
import requests

# Feedly

feedaccess = "REMOVED"
myfeedid = "user/REMOVED/category/tutorial"

def get_feed_content(unreadOnly=None, newerThan=None, count="10",
                         continuation=None,
                         ranked=None):
        """
        return contents of a feed
        :param access_token:
        :param streamId:
        :param unreadOnly:
        :param newerThan:
        :param count:
        :param continuation:
        :param ranked:
        :return:
        """

        headers = {'Authorization': 'OAuth ' + feedaccess}
        quest_url = ('http://cloud.feedly.com/v3/streams/contents')
        params = dict(streamId=myfeedid)
        # Optional parameters
        if unreadOnly is not None:
            params['unreadOnly'] = unreadOnly
        if newerThan is not None:
            params['newerThan'] = newerThan
        if count is not None:
            params['count'] = count
        if continuation is not None:
            params['continuation'] = continuation
        if ranked is not None:
            params['ranked'] = ranked
        res = requests.get(url=quest_url, params=params, headers=headers)
        return res.json()

con = get_feed_content()
print json.dumps(con , indent=4)

TERMINAL

{
    "items": [],
    "id": "user/REMOVED/category/tutorial"
}

只需返回我的用户凭据即可。 Feedly文档说我可以使用类别作为流ID。 https://developer.feedly.com/v3/streams/

第三次尝试

import json
import requests
from client import FeedlyClient

# Feedly

feedaccess = "REMOVED"
myfeedid = "user/REMOVED/category/tutorial"
feedcount = "20"
myurl = "http://cloud.feedly.com/v3/streams/contents?streamId=" + myfeedid + "&count=" + feedcount


headers = {'Authorization': 'OAuth ' + feedaccess}
res = requests.get(url=myurl, headers=headers)
con = res.json()
print json.dumps(con , indent=4)

相同的终端响应

1 个答案:

答案 0 :(得分:0)

第三次尝试奏效了。我的类别名称中有大写字母。它应该是教程而不是教程。请参阅原始帖子以获取代码。