簡體   English   中英

Python 2.7:Imgur 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具有以下屬性: idimage_idcommentauthorauthor_idon_albumalbum_coverupsdownspointsdatetimeparent_iddeletedvotechildren

您可以通過訪問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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM