簡體   English   中英

使用 url 可靠地從 facebook graph api 獲取抓取的數據

[英]Get scraped data from facebook graph api using url reliably

我的應用程序需要從 URL 獲取數據 facebook 抓取。 到目前為止,我們一直在使用它

POST /?id={object-instance-id or object-url}&scrape=true

https://developers.facebook.com/docs/sharing/opengraph/using-objects中的更新對象部分中有詳細說明

例如

POST /?id=http://google.com
{
  "url": "http://www.google.com/",
  "type": "website",
  "title": "Google",
  "image": [
  {
  "url": "http://www.google.com/images/branding/googleg/1x/googleg_standard_color_128dp.png"
    }
  ],
  "description": "Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for.",
  "updated_time": "2015-10-06T11:34:58+0000",
  "id": "381702034999"
}

注意圖片部分。

不幸的是,如果 og 標簽在服務器上配置錯誤

POST /?id=http://some.page.with.bad.tags.com
{
  "error": {
    "message": "Invalid parameter",
    "type": "FacebookApiException",
    "code": 100,
    "error_subcode": 1611016,
    "is_transient": false,
    "error_user_title": "Object Invalid Value",
    "error_user_msg": "Object at URL 'http://some.page.with.bad.tags' of type '' is invalid because the given value '/some-bad-value' for property 'og:url' could not be parsed as type 'url'.",
    "fbtrace_id": "abcabcabc"
  }

}

它沒有返回任何有趣的東西。

嘗試獲取 url 返回:

{
  "og_object": {
    "id": "381702034999",
    "description": "Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for.",
    "title": "Google",
    "type": "website",
    "updated_time": "2015-10-06T11:40:04+0000",
    "url": "http://www.google.com/"
  },
  "share": {
    "comment_count": 2,
    "share_count": 13494003
  },
  "id": "http://www.google.com"
}

哪個錯過了圖像部分。 我在文檔中找不到任何方法來檢索圖像結果而不使用 POST /?id={url},但是在 og 標簽中出現任何錯誤時都會失敗。

GET /{ObjectId}

只返回類型和 created_time

https://developers.facebook.com/tools/debug/ 中輸入相同的斷開鏈接會導致頁面包含該頁面的圖像、描述、標題和標題。 我需要的。 所以這意味着 facebook 存儲它們,即使頁面有錯誤的標簽,但我需要一種方法來獲取它們。 不幸的是,由於保密協議,我無法提供損壞 url 的鏈接,而且我找不到其他帶有損壞標簽的頁面。

如果頁面包含無效的 Open Graph 標記,這似乎是意料之中的,也不要將 Graph API 與某種數據源或可用於生成 Web 內容預覽的抓取服務混淆。

如果 Facebook 出於某種原因無法解析 URL 的 Open Graph 標簽,它將嘗試根據頁面內容(大量文本、找到的圖像、標題標簽等)進行正確的猜測以構建預覽,因此您可能會從GET /{object-id}獲取某種數據,這只是猜測而不是實際的og:..數據。

如果您確實需要或多或少的故障安全解決方案,您可以構建自己的抓取工具來查找 Open Graph 標簽。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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