简体   繁体   English

Facebook 图 API,内容未被正确抓取

[英]Facebook Graph API, content not being scraped properly

I have created a Facebook Canvas App.我创建了一个 Facebook Canvas 应用程序。 This canvas app is essentially an image library, the user is able to view images by clicking a 'Next' button - pretty simple.这个 canvas 应用程序本质上是一个图像库,用户可以通过单击“下一步”按钮来查看图像——非常简单。

I am using the Graph API to post to a custom object when a user has 'looked at' an image.当用户“查看”图像时,我正在使用图形 API 发布到自定义 object。 I do this like so (PHP SDK):我这样做(PHP SDK):

$this->data['facebook']->api('/me/myapp:look_at', 'post', array(
        'picture' => current_url()
    ));

current_url() is the current URL of the Facebook canvas (https://apps.facebook.com/myapp/image/id). current_url() 是 URL 的 Facebook canvas (https://apps.facebook.com/myapp/image/id)。 This page has a series of og meta tags:此页面有一系列 og 元标记:

   <meta property="og:title" content="<?=$image->title?>" />
   <meta property="og:description" content="Pic of <?=$image->title?>" />
   <meta property="og:image" content="https://www.***.com/***/images/<?=$image->src?>" />
   <meta property="fb:app_id" content="<?=FB_APP_ID?>" />
   <meta property="og:url" content="<?=current_url();?>" />
   <meta property="og:type" content="myapp:picture" />

I have read that when adding the image to the library I need to get Facebook to scrape the page for the og:tags.我已经读到,将图像添加到库中时,我需要获取 Facebook 来抓取 og:tags 的页面。 I do this using the following:我使用以下方法执行此操作:

file_get_contents('https://graph.facebook.com?id=https://apps.facebook.com/myapp/image/'.url_title($_POST['title']).'/'.$data['image_id'].'&scrape=true');

However, I'm pretty certain that this isn't working, after placing a mail() call in the app, visiting that URL and waiting nothing comes through, suggesting that it isn't being scraped.但是,我很确定这是行不通的,在应用程序中调用 mail() 后,访问了 URL 并等待没有任何通过,这表明它没有被抓取。

When running the first block of code (calling Graph API myapp:look_at) I get the following exception from Facebook:运行第一段代码时(调用 Graph API myapp:look_at)我从 Facebook 得到以下异常:

Fatal error: Uncaught OAuthException: (#3502) Object at URL https://apps.facebook.com/myapp/image/img/id has og:type of 'website'. The property 'picture' requires an object of og:type 'myapp:picture'. thrown in /****/application/libraries/base_facebook.php on line 1106

If I use Facebook's debugger tool to scrape the page I get all of the info.如果我使用 Facebook 的调试器工具来抓取页面,我将获得所有信息。 If I then revisit the canvas page where the FB Graph API call is made then everything goes through fine.如果我随后重新访问调用 FB Graph API 的 canvas 页面,那么一切都会顺利进行。 I have read on other SO posts that this is a common problem, and I need to ask Facebook to scrape the page before calling the Graph API, which is precisely what I'm trying to do in the third block of code above (file_get_contents) without luck.我在其他 SO 帖子上读到这是一个常见问题,在调用图形 API 之前我需要先请求 Facebook 抓取页面,这正是我在上面的第三个代码块 (file_get_contents) 中尝试做的事情没有运气。

I guess my question would be: Am I going about this in the right way?我想我的问题是:我是否以正确的方式处理这件事? I am struggling to find any clear documentation on the process when it is used in this way.当以这种方式使用它时,我很难找到关于该过程的任何明确文档。

If I am going about it the right way, why is my page not being scraped when calling file_get_contents('https://app....)?如果我以正确的方式处理它,为什么在调用 file_get_contents('https://app....) 时我的页面没有被抓取?

Sorry for the long post, I'm trying to give you the full picture.抱歉发了这么长的帖子,我想给你完整的图片。

Thanks谢谢

You shouldn't need to do the manual scrape to get the object to register.您不需要手动抓取 object 进行注册。 According to the Facebook documentation:根据 Facebook 文档:

When your app tries to make a connection between the user and the object via an action on Open Graph, Facebook will scrape the object webpage and read the meta tags to associate the user with the object. The object scrape occurs when:当您的应用尝试通过对 Open Graph 的操作在用户和 object 之间建立连接时,Facebook 将抓取 object 网页并读取元标记以将用户与 object 相关联。object 抓取发生在以下情况:

  • A user, for the first time, takes an action on the object (such as: like, listen, read, or any custom action on the object).用户第一次对 object 执行操作(例如:喜欢、收听、阅读或对该对象的任何自定义操作)。 Learn more学到更多
    about how to publish actions.关于如何发布动作。
  • List item项目清单
  • Linting the object URL via the Object Debugger通过 Object 调试器检查 object URL
  • Linting the object URL via the Linter API Every 7 days after the first scrape Linting the object URL 通过 Linter API 在第一次抓取后每 7 天

If the publishing code is called, the connected object will be scraped automatically if its the first time being referenced.如果调用发布代码,连接的object如果是第一次被引用,会被自动抓取。 Otherwise using the debugger, as you mentioned have already doing, will have the same effect.否则,正如您提到的那样,使用调试器会产生相同的效果。

EDIT-> However, there are some inconsistencies (as you mentioned) and developers noting their "fresh" objects not being scraped properly.编辑-> 但是,存在一些不一致(如您所提到的),开发人员注意到他们的“新鲜”对象没有被正确抓取。 Facebook not this bug and will hopefully sort it out soon. Facebook 不是这个错误,希望能尽快解决。 A work around seems to be to force linting the items using the debugger.解决方法似乎是使用调试器强制对项目进行 linting。

https://developers.beta.facebook.com/bugs/141650809281976/?browse=search_4f488911648042f90826189 https://developers.beta.facebook.com/bugs/141650809281976/?browse=search_4f488911648042f90826189

Documentation:https://developers.facebook.com/docs/opengraph/objects/#connect文档:https://developers.facebook.com/docs/opengraph/objects/#connect

Hope this helps:) Good luck希望这有帮助,祝你好运

Fixed it.固定它。 I needed a user-agent check on the code that posts the Graph API to prevent that from posting when FB hits it:我需要对发布图形 API 的代码进行用户代理检查,以防止在 FB 访问它时发布该代码:

if(strpos($_SERVER['HTTP_USER_AGENT'], 'facebookexternalhit') === false)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Facebook开放图元标记未为我的Laravel网站报废 - Facebook Open Graph Meta Tags Not Being Scraped For My Laravel Site 使用 url 可靠地从 facebook graph api 获取抓取的数据 - Get scraped data from facebook graph api using url reliably 无法解决Facebook Open Graph Meta标签没有被我的Wordpress网站刮掉 - Can't solve Facebook Open Graph Meta tags not being scraped for my Wordpress site Facebook Graph API需要字段内容 - Facebook Graph API require content for field 如何通过Graph API获取Facebook保存的内容? - how to get facebook saved content by Graph API? Facebook PHP SDK Graph API发布到页面无法正常运行 - Facebook PHP SDK Graph API post to page not functioning properly (#100)图片网址的格式不正确-Graph API Facebook - (#100) picture URL is not properly formatted - Graph API Facebook 如何在 Javascript 中正确生成 Facebook Graph API App Secret Proof - How to properly generate Facebook Graph API App Secret Proof in Javascript 查询Facebook是否正在使用/可以使用的是什么版本的Graph API - Query Facebook for what version of the Graph API is being used / can be used Facebook Open Graph API - og:被忽略的元标记 - Facebook Open Graph API - og:metatags being ignored
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM