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

标签 facebook facebook-graph-api facebook-php-sdk

我创建了一个 Facebook Canvas 应用程序。这个 Canvas 应用程序本质上是一个图像库,用户可以通过单击“下一步”按钮来查看图像 - 非常简单。

当用户“查看”图像时,我使用图形 API 发布到自定义对象。我这样做(PHP SDK):

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

current_url() 是 Facebook Canvas 的当前 URL (https://apps.facebook.com/myapp/image/id)。此页面有一系列 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" />

我读到在将图像添加到库时我需要让 Facebook 抓取 og:tags 的页面。我使用以下方法执行此操作:

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

但是,我很确定这是行不通的,在应用程序中调用 mail() 后,访问该 URL 并等待任何内容通过,这表明它没有被抓取。

当运行第一个代码块(调用 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

如果我使用 Facebook 的调试器工具来抓取页面,我将获得所有信息。如果我随后重新访问进行 FB Graph API 调用的 Canvas 页面,那么一切都会顺利进行。我在其他 SO 帖子上读到这是一个常见问题,我需要在调用 Graph API 之前要求 Facebook 抓取页面,这正是我在上面的第三个代码块 (file_get_contents) 中尝试做的事情没有运气。

我想我的问题是:我这样做的方式是否正确?当以这种方式使用它时,我很难找到关于该过程的任何明确文档。

如果我的做法是正确的,为什么在调用 file_get_contents('https://app....) 时我的页面没有被抓取?

抱歉发了这么长的帖子,我想给你完整的图片。

谢谢

最佳答案

您不需要手动抓取来注册对象。 根据 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:

  • A user, for the first time, takes an action on the object (such as: like, listen, read, or any custom action on the object). Learn more
    about how to publish actions.
  • List item
  • Linting the object URL via the Object Debugger
  • Linting the object URL via the Linter API Every 7 days after the first scrape

如果调用发布代码,连接的对象在第一次被引用时会被自动抓取。 否则,正如您提到的那样,使用调试器会产生相同的效果。

EDIT-> 但是,存在一些不一致(如您所提到的),开发人员注意到他们的“新鲜”对象没有被正确抓取。 Facebook 不是这个错误,希望能尽快解决。解决方法似乎是使用调试器强制对项目进行 linting。

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

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

希望这有帮助:)祝你好运

关于Facebook Graph API,内容未被正确抓取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10087970/

相关文章:

ios - facebook 广告设置的问题

php - 从页面或应用程序发布到 Facebook 用户的留言墙上

ios - 获取facebook用户生日和电话号码

ios - 在不使用 CocoaPod 的情况下安装 iOS Facebook SDK

java - 从 Facebook 墙阅读的应用程序

javascript - 如何转发 Facebook 帖子

php - Facebook PHP SDK v4.0.0 : $session is not set even after authorizing facebook from the login URL

javascript - Facebook API 没有响应

facebook - 处理存在的用户,但尝试通过 Facebook OAuth/etc 登录

c# - 使用 Graph API 计算 Facebook "Likes"