0
votes

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
I think you didn't understand the original code example, your parameters don't need the "og:" part, simply http://...?type=...&title=... and so on, also app_id is not parameterized in your pasted code.complex857
MY_APP_ID is replace with the real app ID.I removed the og: in the url and the error still persist.darrenbkl
You might need to encode your URL parameters for facebook debug tool, charachters like / or ':` doesn't allowed in query string. See what rawurlencode prints for your individual GET parameters.complex857

1 Answers

0
votes
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