简体   繁体   English

使用Facebook Open Graph API创建对象

[英]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. 我使用Google App Engine托管我的Facebook应用程序,因为它在配额方面是最慷慨的。 I would like to use the Open Graph API to publish actions (cook a pizza, cook a chicken, cook a pie, etc.) 我想使用Open Graph API来发布操作(煮披萨,煮鸡,煮馅饼等)。

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. 由于Python Facebook SDK现在已过时,我想知道是否有人可以就我的应用程序可以访问的功能来解释我的应用程序的局限性。 It seems like I can use the JavaScript SDK to authenticate the user, publish actions, etc. 看来我可以使用JavaScript SDK来验证用户身份,发布操作等。

Here is my meta tags at the html client-side of my app interface: 这是我的应用程序界面的html客户端上的元标记:

<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? 是否可以在发布操作之前使用AJAX检索值并更改“ Sample Chemical”值? 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. 在Facebook抓取它们之前,您无法使用Javascript动态设置元标记。 You must do it from server side. 您必须从服务器端执行此操作。 However, what you want to accomplish here doesn't require you to use the Facebook SDK. 但是,您要在此处完成的操作不需要您使用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. 这是一个有关如何执行此操作的PHP示例: 动态生成Facebook Open Graph元标记我相信您可以将该代码传输到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. 当Facebook搜寻器点击表示并标识您的Open Graph对象(例如化学药品)的URI时,它将解析OG标签并将该数据与URI一起存储为标识符。

As such, you would have a URI http://example.com/chemicals/1 render 这样,您将获得一个URI http://example.com/chemicals/1呈现器

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

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

...
<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). 这是一个动态页面,该页面响应URI末尾的数字作为查询化学数据库的参数:(ERB示例)。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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