2015-05-04 145 views
6

我正在編寫一個應用程序,它必須獲取PHP中Tumblr文章的喜歡數量。我正在使用Tumblr PHP library,並已成功通過身份驗證和所有。我使用Client::getBlogPosts()獲取帖子列表。它返回什麼本質上是一個PHP陣列類似的信息:Tumblr API:有沒有辦法獲得Tumblr博客收到的喜歡數量?

{ 
    "blog_name": "jeteon", 
    "id": 92729317211, 
    "post_url": "http://jeteon.tumblr.com/post/92729317211/where-to-find-libxm-so-2-for-ubuntu", 
    "slug": "where-to-find-libxm-so-2-for-ubuntu", 
    "type": "link", 
    "date": "2014-07-24 13:43:04 GMT", 
    "timestamp": 1406209384, 
    "state": "published", 
    "format": "html", 
    "reblog_key": "oA2WcGac", 
    "tags": [ 
     "dakota", 
     "ubuntu" 
    ], 
    "short_url": "http://tmblr.co/Z9ROeu1MN6HTR", 
    "highlighted": [], 
    "note_count": 0, 
    "title": "Where to find libXm.so.2 for Ubuntu", 
    "url": "https://packages.debian.org/wheezy/lesstif2", 
    "author": null, 
    "excerpt": null, 
    "publisher": "packages.debian.org", 
    "description": "<p>I recently had to install Dakota (<a href=\"http://dakota.sandia.gov\">http://dakota.sandia.gov</a>) and after considerable trouble with prerequisites, found that the binary install on Ubuntu requires (amonst other umentioned libraries) a shared library called libXm.so.2. The library is in a package called lesstif2 which is no longer available, it seems. You can grab the DEB on the above link though.</p>", 
    "reblog": { 
     "tree_html": "" 
    }, 
    "trail": [ 
     { 
     "blog": { 
      "name": "jeteon", 
      "theme": { 
      "avatar_shape": "square", 
      "background_color": "#FAFAFA", 
      "body_font": "Helvetica Neue", 
      "header_bounds": "", 
      "header_image": "http://assets.tumblr.com/images/default_header/optica_pattern_10.png?_v=eafbfb1726b334d86841955ae7b9221c", 
      "header_image_focused": "http://assets.tumblr.com/images/default_header/optica_pattern_10_focused_v3.png?_v=eafbfb1726b334d86841955ae7b9221c", 
      "header_image_scaled": "http://assets.tumblr.com/images/default_header/optica_pattern_10_focused_v3.png?_v=eafbfb1726b334d86841955ae7b9221c", 
      "header_stretch": true, 
      "link_color": "#529ECC", 
      "show_avatar": true, 
      "show_description": true, 
      "show_header_image": true, 
      "show_title": true, 
      "title_color": "#444444", 
      "title_font": "Gibson", 
      "title_font_weight": "bold" 
      } 
     }, 
     "post": { 
      "id": "92729317211" 
     }, 
     "content": "<p>I recently had to install Dakota (<a href=\"http://dakota.sandia.gov\">http://dakota.sandia.gov</a>) and after considerable trouble with prerequisites, found that the binary install on Ubuntu requires (amonst other umentioned libraries) a shared library called libXm.so.2. The library is in a package called lesstif2 which is no longer available, it seems. You can grab the DEB on the above link though.</p>", 
     "is_root_item": true, 
     "is_current_item": true 
     } 
    ] 
    } 

什麼,我正在尋找最接近的領域是note_count,雖然這兩者聚合的喜好和reblogs。如果note_count爲0,那麼沒有問題,但是當筆記計數爲41時,我無法分辨它是否已經被喜歡40次,並且只有一次或相反。無論哪種方式,liked字段的存在與否都已告訴您這一點。

我嘗試使用Client::getBlogLikes()方法,但它檢索博客喜歡的帖子列表(用Tumblr的說法,有效地發佈了創建用戶喜歡的帖子),這與我正在尋找的反面相反。

我可以從一般的互聯網中獲得最好的就是這個article,這表明使用URL api.tumblr.com/v2/blog/{base-hostname}/likes?api_key={key},但作爲就我所知,從代碼中可以看出,這與使用Tumblr PHP庫中的Client::getBlogLikes()函數相同。

有沒有人知道一種方法來獲得特定帖子收到的喜好數量?它不需要是一個PHP特定的解決方案。

+1

其可悲不可能。 'note_count'是喜歡和reblogs的組合:http://tumblr.com/docs/en/api/v2#posts – mikedidthis

+0

可能的重複:http://stackoverflow.com/questions/29820031/how-to-get-個體tumblr-職位 - 喜歡 - 數換tumblr客戶端,寶石 – mikedidthis

回答

1

如果任何人在原始帖子後仍然搜索這2年......您可以通過在您的api電話上追加&notes_info=true來完成此操作 - 將返回一個notes對象的集合。如果你遍歷這些,你可以計算帖子類型。從我可以看到的帖子類型是:posted(原文),likereblog。希望這可以幫助!

實施例從json響應注意到集合:(僅示出1注)

'notes': [{'avatar_shape': 'square', 
      'blog_name': 'xxx', 
      'blog_url': 'xxx', 
      'blog_uuid': 'xxx', 
      'followed': False, 
      'timestamp': 1505922448, 
      'type': 'like'}], 
1

看起來好像是Tumblr API v2 docs,那不行,這是不可能的。你只能得到博客喜歡的總數或人們喜歡的帖子。