简体   繁体   中英

Creating objects with the Facebook Open Graph API

I am using Google App Engine to host my Facebook Application because it is the most generous in terms of quota. I would like to use the Open Graph API to publish actions (cook a pizza, cook a chicken, cook a pie, etc.)

Since the Python Facebook SDK is now deprecated, I was wondering if someone can explain the limitations of my app in terms of what features it is able to access. It seems like I can use the JavaScript SDK to authenticate the user, publish actions, etc.

Here is my meta tags at the html client-side of my app interface:

<meta property="fb:app_id"      content="250027595026486" /> 
<meta property="og:type"        content="socialdocking:chemical" /> 
<meta property="og:url"         content="http://beta2.socialdocking.appspot.com/" /> 
<meta property="og:title"       content="Sample Chemical" /> 
<meta property="og:description" content="Some Arbitrary String" /> 
<meta property="og:image"       content="https://s-static.ak.fbcdn.net/images/devsite/attachment_blank.png" />

How can I have different values for 'Sample Chemical' the 'Chemical' without manually writing it from the server? Is it possible to retrieve a value using AJAX and change the value "Sample Chemical" before publishing the action? In other words, do I have to abide by the design that an Open Graph "Object" is represented by a single web page, or can I use a single web page to represent multiple objects simultaneously?

Thanks!

You cannot set meta tags dynamically with Javascript before Facebook scrapes them. You must do it from server side. However, what you want to accomplish here doesn't require you to use the Facebook SDK. Here is a PHP example on how to do it: Generating Facebook Open Graph meta tags dynamically I'm sure you can transfer that code into Python.

When the Facebook crawler hits the URI representing and identifying your Open Graph object (say, a chemical), it will parse the OG tags and store that data with the URI as an identifier.

As such, you would have a URI http://example.com/chemicals/1 render

...
<meta property="og:title"       content="Potassium Nitrate" />
<meta property="og:description" content="totse.com was really cool" />
...

and http://example.com/chemicals/2 render

...
<meta property="og:title"       content="Whateverium Sulfate" />
<meta property="og:description" content="This makes things go boom." />
...

To make this clearer, here's what's happening. This is a dynamic page, which responds to the number at the end of the URI as a parameter for querying your chemical database: (ERB example).

...
<meta property="og:title"       content="<%= @chemical.name %>" />
<meta property="og:description" content="<%= @chemical.description %>" />
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM