Facebook并没有按照OG元标记一致地抓取信息

时间:2015-04-30 09:06:18

标签: python django facebook graph

我使用Python的facebook模块自动在会员的Facebook页面上发布人们工作的广告。我申请并获得了Facebook的权力。现在,当我发布到大多数人的页面时,图像和描述都没有被删除,但是当我使用与应用程序关联的业务站点的FB站点所有者访问令牌发布时,它们就是。 我用来发布页面的代码:

  import facebook
  graph       = facebook.GraphAPI(access_token)
  # record the id of the wall post so we can like it
  fbWallPost  = graph.put_wall_post(message=fbmsg,  attachment=fbpost, profile_id=pageID)

在python shell中运行它会发布一个被抓取的URL,但是从应用程序中运行它经常不会。该页面包含以下元标记:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">

  <title>Fair Work</title>


  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="author" content="Fair Work">
    <!-- Facebook crawler uses these JRT -->
  <meta property="og:site_name" content="Fair Work"/>
  <meta property="fb:app_id" content="322643981237986" />


  <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
  <meta http-equiv="Pragma" content="no-cache" />
  <meta http-equiv="Expires" content="0" />


  <meta property="og:url" content="http://fairwork.com.au/job/final-job-on-thursday-april-30th/" />
  <meta property="og:description" content="My last test today"/>
  <meta property="og:type" content="article"/>

  <meta property="og:image" content="http://fairwork.com.au/media/cache/cd/b0/cdb05f8dd8885351925bf43076870937.jpg"/>
  <meta property="og:image:width" content="400" />
  <meta property="og:image:height" content="400" />

应用程序ID正确无误。我转到Facebook的调试器,然后输入URL My URL given to FB debugger
我点击“Debug”,我收到一个错误,“og:type”元标记丢失,这不是你可以看到的: enter image description here 然后我点击“获取新的刮擦信息”... enter image description here ...并且图像和描述加载得很好。从这一点开始,如果我在我的网站上发布链接,则显示图像和描述,但是所有先前发布的链接都没有抓取信息。下一个图像中相同链接的两个连续帖子在执行前面提到的调试过程之前(底部)和之后(顶部)完成: enter image description here

链接到的页面是公共可用的,由Django提供。我希望能够自动发布广告(当FB页面所有者请求时),并在发布时由FB抓取图像和描述。有什么想法吗?

1 个答案:

答案 0 :(得分:1)

似乎NGINX导致对Facebook图形API的http调用无法正常工作。什么时候

fbWallPost  = graph.put_wall_post(message=fbmsg,  attachment=fbpost, profile_id=pageID)

通过Celery运行(它分别运行到django,而不是通过Web服务器),facebook擦除发布的链接并显示由OG元标记链接的图像和描述。当django运行put_wall_post时,帖子会发生,但facebook不会刮掉链接。从Django视图运行时,对API的其他调用也不起作用。我只能认为NGINX在某种程度上干扰了HTTP请求。

相关问题