Facebook Open Graph,未提供“string”类型所需属性“og:title” [英] Facebook Open Graph, required property 'og:title' of type 'string' was not provided

查看:1256
本文介绍了Facebook Open Graph,未提供“string”类型所需属性“og:title”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Joomla页面(v3.2.4),我用PHP放入了一些动态的Open Graph标签,如下所示:



在标签之前的PHP :

  $ getcid = JRequest :: getVar('id'); 

if(!isset($ getcid)){
$ title =LIVA Kurser;
$ description =Danmarksstørsteudbyder af kurser tilsåveloffentlige og erhverv samt private。
$ image =http://www.livakursertestsite.dk/images/liva-logo.jpg;
$ type =website;
} else {
$ db = JFactory :: getDbo();
$ user = JFactory :: getUser();
$ query = $ db-> getQuery(true);
$ ogquery =SELECT DISTINCT * FROM jos_managecourse WHERE state ='1'AND id ='。$ getcid。'LIMIT 1;
$ db-> setQuery($ ogquery);
$ db-> query();
$ getcourse = $ db-> loadObjectList();

$ description = substr(strip_tags($ getcourse [0] - >细节),0,247);
$ title = $ getcourse [0] - > course_name;

$ description = preg_replace(/ \r\\\
/,,$ description);
$ description = str_replace(& nbsp;,,$ description);

$ image = JURI :: root()。administrator / components / com_managecourse / images /\".$ getcourse [0] - > image_url;
$ type =article;
}

在我的标签中我有:

 <! -  Facebook Open Graph  - > 
< meta property =fb:app_idcontent =502033806595590/>
< meta property =og:site_namecontent =LIVA Kurser/>
< meta property =og:typecontent =<?php echo $ type;?> />
< meta property =og:titlecontent =<?php echo $ title;?> />
< meta property =og:urlcontent =<?php echo JURI :: current();?> />
< meta property =og:imagecontent =<?php echo $ image;?> />
< meta property =og:descriptioncontent =<?php echo $ description;?> .../>
<! - 结束Facebook Open Graph - >

当我通过 Facebook对象调试器,我收到以下两个错误:


对象在URL'类型网站的href =http://www.livakursertestsite.dk/kurser/babytegn-2> http://www.livakursertestsite.dk/kurser/babytegn-2 无效,因为未提供必需的属性og:title
类型'string'。


而第二个错误:


卷曲错误:BAD_CONTENT_ENCODING处理内容时出错
unencoding:无效块类型


我尝试过:




  • 移动标题标签下方的代码

  • 将其移动到标题的顶部和底部,但
    不起作用。

  • 将PHP代码放入标签,但仍然没有。



您可以在这里查看该网站: http://www.livakursertestsite.dk/kurser/babytegn- 2



编辑:



代码从标签,所以他们不再是动态的,看看是否是原因,但不是。现在代码如下所示:

 < meta property =og:localecontent =da_DK/> 
< meta property =og:typecontent =website/>
< meta property =og:titlecontent =LIVA Kurser/>
< meta property =og:descriptioncontent =Beskrivelse .../>
< meta property =og:urlcontent =http://www.livakursertestsite.dk/kurser/>
< meta property =og:imagecontent =http://www.livakursertestsite.dk/images/liva-logo.jpg/>
< meta property =fb:app_idcontent =502033806595590/>
< meta property =og:site_namecontent =LIVA Kurser/>

我现在也试过:




  • 谷歌丰富网页摘要测试工具
    Google上测试网站所有数据。

  • 删除所有不必要的打开图形标签,因此只有四个强制性标签(类型,标题,网址和图像)存在。

  • 删除所有在Firebug中导致错误的javascript。



而Facebook调试器仍然无法获取数据。 p>

编辑#2:



在@CBroe的评论之后,我修复了页面,所以它可以被验证,没有错误,但仍然没有运气。

解决方案

你可能想尝试禁用任何压缩,例如PHP中的GZIP压缩。这有助于我在Joomla 3.3网站中遇到类似的问题。



我启用了GZIP压缩,Facebook无法抓住我的网站。禁用GZIP压缩解决了这个问题。



我还没有想到,如果它是一个Joomla问题,或者一般的GZIP / PHP问题或Facebook的scrape问题。 p>

编辑:通过共享操作,Facebook只会读取您的第一个40k的页面。当GZIP启用时,只读第一个40k将会出现问题,因为它无法解压缩部分内容。



更好的解决方案是禁用GZIP, Facebook,LinkedIn等。



您可以使用名为gzip的小插件非常友好控制: http://extensions.joomla.org/extensions/core-enhancements/performance/site-performance/27725



或使用此代码 https://github.com/dgt41/ (zip的xml和php文件,你可以安装它作为插件)



请注意:如果您的JCH Optimize模块安装在您的网站上,您将需要禁用gzip插件提供的压缩所有其他选项可以保持激活,无任何问题,包括本机Joomla gzip压缩。



干杯,
Teeuwis


I have a Joomla-page (v3.2.4) where I put in some dynamic Open Graph tags with PHP, like this:

The PHP, before the tag:

$getcid = JRequest::getVar('id');

if(!isset($getcid)) {
$title = "LIVA Kurser";
$description = "Danmarks største udbyder af kurser til såvel offentlige og erhverv samt private.";
$image = "http://www.livakursertestsite.dk/images/liva-logo.jpg";
$type = "website";
} else {
$db = JFactory::getDbo();
$user    = JFactory::getUser();
$query = $db->getQuery(true);
$ogquery = "SELECT DISTINCT * FROM jos_managecourse WHERE state = '1' AND id = '".$getcid."' LIMIT 1";
$db->setQuery($ogquery);
$db->query();
$getcourse = $db->loadObjectList();  

$description = substr(strip_tags($getcourse[0]->details), 0, 247);
$title = $getcourse[0]->course_name;

$description = preg_replace( "/\r|\n/", "", $description );
$description = str_replace( "&nbsp;", " ", $description );

$image = JURI::root()."administrator/components/com_managecourse/images/".$getcourse[0]->image_url;
$type = "article";
}

And in my tag I have this:

  <!-- Facebook Open Graph -->
  <meta property="fb:app_id" content="502033806595590" />
  <meta property="og:site_name" content="LIVA Kurser" />
  <meta property="og:type" content="<?php echo $type; ?>" />
  <meta property="og:title" content="<?php echo $title; ?>" />
  <meta property="og:url" content="<?php echo JURI::current(); ?>" />
  <meta property="og:image" content="<?php echo $image; ?>" />
  <meta property="og:description" content="<?php echo $description; ?>..." />
  <!-- End Facebook Open Graph -->

When I run the page through the Facebook Object Debugger, I get the following two errors:

Object at URL 'http://www.livakursertestsite.dk/kurser/babytegn-2' of type 'website' is invalid because a required property 'og:title' of type 'string' was not provided.

And the second error:

Curl Error : BAD_CONTENT_ENCODING Error while processing content unencoding: invalid block type

I have tried:

  • Moving the code below and above the title-tag
  • Moving it to the very top and very bottom of the head-tag, but neither works.
  • Putting the PHP-code in the head-tag, but still nothing.

You can see the site here: http://www.livakursertestsite.dk/kurser/babytegn-2

EDIT:

I have removed the PHP-code from the tags, so they are no longer dynamic, to see if that was the cause, but it wasn't. Now the code looks like this:

<meta property="og:locale" content="da_DK" />
<meta property="og:type" content="website" />
<meta property="og:title" content="LIVA Kurser" />
<meta property="og:description" content="Beskrivelse..." />
<meta property="og:url" content="http://www.livakursertestsite.dk/kurser" />
<meta property="og:image" content="http://www.livakursertestsite.dk/images/liva-logo.jpg" />
<meta property="fb:app_id" content="502033806595590" />
<meta property="og:site_name" content="LIVA Kurser" />

I have now also tried:

  • Testing the site on Googles Rich Snippets testing tool, and Google gets all the data.
  • Removing all not-obligatory Open Graph-tags, so only the four obligatory tags (type, title, url and image) was present.
  • Removing all javascript which caused errors in Firebug.

And the Facebook Debugger still can't get the data.

Edit #2:

After the comment by @CBroe I fixed the page, so it could be validated, with no errors, but still no luck.

解决方案

You might want to try to disable any sort of compression, for example GZIP compression in PHP. This helped me with a similar problem in a Joomla 3.3 website.

I had GZIP compression enabled and Facebook was unable to scrape my website. Disabling the GZIP compression solved that issue.

I have not figured out yet if it's a Joomla problem or a GZIP/PHP problem in general or a facebook scrape problem.

EDIT: With a share action, Facebook only reads the first 40k of your page. When GZIP is enabled, reading only the first 40k will give problems as it is unable to decompress the partial contents.

A better solution would be to disable GZIP only for sites like Facebook, LinkedIn, etc.

You can use the small plugin called gzip very friendly Control: http://extensions.joomla.org/extensions/core-enhancements/performance/site-performance/27725

Or use this codee https://github.com/dgt41/ (zip the xml and php file and you can install it as a plugin)

Please note: If you have JCH Optimize module installed on your site you will need to disable gzip compression offered by the plugin. All other options can remain activated without any problems, including a native Joomla gzip compression.

Cheers, Teeuwis

这篇关于Facebook Open Graph,未提供“string”类型所需属性“og:title”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆