dongzhenshen7435 2012-07-31 09:28
浏览 111

Facebook Open Graph Object动态网页

So I'm making an iPhone app that involve sharing through Facebook open graph protocol.However I'm stuck while creating a dynamic webpage for the object with meta tag. I came across this post, Generating Facebook Open Graph meta tags dynamically, and tried using the code, but it doesn't work.

This is my food.php object webpage.

<?php

$params = array();
if(count($_GET) > 0) {
    $params = $_GET;
} else {
    $params = $_POST;
}

// defaults
if($params['type'] == "") $params['type'] = "food";
if($params['title'] == "") $params['title'] = "default title";
if($params['image'] == "") $params['image'] = "blank";
if($params['description'] == "") $params['description'] = "default description";

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

    <head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# MY_APP_NAME_SPACE: http://ogp.me/ns/fb/MY_APP_NAME_SPACE#">

        <!-- Open Graph meta tags -->
        <meta property="fb:app_id" content="MY_APP_ID" />
        <meta property="og:url" content="http://mysite.com/index.php?type=<?php echo $params['type']; ?>&title=<?php echo $params['title']; ?>&image=<?php echo $params['image']; ?>&description=<?php echo $params['description']; ?>"/>
        <meta property="og:type" content="MY_APP_NAME_SPACE:<?php echo $params['type']; ?>"/>
        <meta property="og:title" content="<?php echo $params['title']; ?>"/>
        <meta property="og:image" content="http://mysite.com/img/<?php echo $params['image']; ?>.jpg"/>
        <meta property="og:description" content="<?php echo $params['description']; ?>"/>

    </head>
</html>

With this code reside in my server, I tried access the page using fb object debugger tool with this url.

http://mysite.com/food.php?fb:app_id=MY_APP_ID
&og:type=MY_APP_NAME_SPACE:food
&og:title=Pizza
&og:description="Pizza"
&og:image=http://mysite.com/img/someImage.jpg

*note there is no space in the url

and the debugger throws this error

Error Parsing URL:Error parsing input URL, no data was scraped.

I suppose the problem lies in the url that I entered because the tool cannot parse it?If not what could it be?

  • 写回答

1条回答 默认 最新

  • dqotv26286 2017-10-06 19:44
    关注
    if($params['description'] == "") $params['description'] = "default description";
    

    "Default description" is actually supposed to be YOUR description of the site that viewers will see because that's what facebook is scraping on your page.

    the variable $params['description']; ?> will output the actuall description in your string. ”/>

    The echo statment is like printing out the actual description and is what facebook's debugger will see.

    You need to pass the values through the URL such as mysite.com/pizza.php?title=pizza&description=whateveryourdescriptionis in order for facebook to scrape that particular page

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题