[英]Response unpacking error in Python 2.7 with python-oauth2 and Imgur's Authenticated API
[英]Python 2.7: Imgur API and getting clear text comments from a post?
client = ImgurClient(client_id, client_secret, access_token, refresh_token)
for item in client.gallery_item_comments("c1SN8", sort='best'):
print item
這是我當前的代碼。 我想做的是(希望)從該函數返回評論ID的列表。 它不這樣做,而是輸出它。
<imgurpython.imgur.models.comment.Comment object at 0x03D8EFB0>
...
我要問的是,是否有來自Imgur api的功能組合以獲得注釋ID的列表? API
在上面的代碼item
是一個Comment
對象,代表注釋本身。 由於它沒有定義的方法來打印對象,因此您可以看到imgurpython.imgur.models.comment.Comment
告訴您對象類型和0x03D8EFB0
表示該對象位於內存中的地址。 不用擔心,這確實是您要查找的評論。
查看Imgur API文檔中的Comment,您可以看到Comment具有以下屬性: id
, image_id
, comment
, author
, author_id
, on_album
, album_cover
, ups
, downs
, points
, datetime
, parent_id
, deleted
, vote
和children
。
您可以通過訪問for循環內的item.<property>
來訪問每個屬性。 例如,如果要打印所有id
,則可以執行以下操作:
client = ImgurClient(client_id, client_secret, access_token, refresh_token)
for item in client.gallery_item_comments("c1SN8", sort='best'):
print item.id
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.