【发布时间】:2018-03-27 19:00:35
【问题描述】:
我正在尝试访问 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)
终端
{
"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)
相同的终端响应
【问题讨论】:
-
您似乎没有遵循该库自述文件中的任何说明来获取有效的客户端对象。
-
我在他们的开发者论坛上阅读了一条评论,即获取访问令牌的过程是通过申请自述文件中所述的代码。我不理解自述文件本身。提供的链接不会指向具有所谓 ID 和密钥的任何地方。论坛中有客户 ID 和机密,每个月都会发布/更新。 Feedly 确实为开发人员生成了一个访问令牌,我认为这可能已经足够好了,因为这些 cmets 是几年前的。将不胜感激更清晰的分步说明。假设我拿到了钥匙。然后呢?我在哪里插入它们?