简体   繁体   English

每个项目都有Facebook点赞按钮吗?

[英]Facebook Like button for every item?

I have Facebook iframe app where I am pulling content with JSON and representing it in a list with search criteria. 我有Facebook iframe应用,我在其中使用JSON提取内容并将其表示在具有搜索条件的列表中。

On item click new content shows on the same page (using ajax), and that page shows more info about item. 在项目上单击新内容将在同一页面上显示(使用ajax),并且该页面上显示有关该项目的更多信息。 I want to add a LIKE button for every clicked item. 我想为每个单击的项目添加一个“喜欢”按钮。

But it must be a different URL so I can publish it on my FB wall. 但是它必须是一个不同的URL,以便我可以将其发布在FB墙上。 So when I check link from Like button on wall, it will redirect me on that special item. 因此,当我从墙上的“喜欢”按钮检查链接时,它将重定向我该特殊项目。

Here are few issues: 这里有几个问题:

1) How to define Like button for every item? 1)如何为每个项目定义“赞”按钮?

<div class="fb-like" data-href="LINK FOR LIKE BUTTON" data-send="true" data-layout="button_count" data-width="450" data-show-faces="true" data-colorscheme="dark"></div>

Here is LIKE button, I need to specify different data-href for every item. 这是LIKE按钮,我需要为每个项目指定不同的data-href。

2) I need to send some parameters to url. 2)我需要发送一些参数到URL。 Let's say when clicking on item, I should send item id to URL. 假设点击商品时,我应该将商品ID发送到URL。 Right now I can send item id to my URL but it is doing just in my iframe -- not in facebook URL. 现在,我可以将商品ID发送到我的URL,但它只是在我的iframe中执行-而不是在Facebook URL中。 How can I do this? 我怎样才能做到这一点?

I think second problem would give an answer for my first problem. 我认为第二个问题可以回答我的第一个问题。

Edit: I am doing this using jQuery. 编辑:我正在使用jQuery。

edit2: so, i am using jquery for my site, pulling content with JSON and representing it with html and jquery, i have, it is all the same page, but on click i hide some contents and show another, so my main content is a list of items, click on item i hide main content, and i show item info content edit2:所以,我在我的网站上使用jquery,使用JSON提取内容并用html和jquery表示它,我的页面都在同一页面上,但是在单击时我隐藏了一些内容并显示了其他内容,所以我的主要内容是项目列表,单击项目,我隐藏主要内容,然后显示项目信息内容

so, it is all one page, so it has the same URL (main content, item content,... all the same URL) 因此,它都是一页,因此具有相同的URL(主要内容,项目内容,...都具有相同的URL)

so for adding LIKE buttons for every item, i need to make a difference between those items, so i done this 因此,为每个项目添加“喜欢”按钮时,我需要在这些项目之间进行区别,所以我做到了

'window.location.href=window.location.href + "#id=" + propertyid;' 

so right now, every item has its own URL, which i done manually, so right now every item has own URL which i could use for LIKE button 所以现在,每个项目都有自己的URL,这是我手动完成的,所以现在每个项目都有自己的URL,我可以将其用于LIKE按钮

but, when i alert this new window.location.href is seems all right, i get this new location with #id=12345 included, but when i try to send that location to LIKE button data-href it is always just the main location, without this new part includind item id #id=12345 但是,当我提醒此新window.location.href似乎还不错时,我获得了包含#id = 12345的新位置,但是当我尝试将该位置发送到LIKE按钮data-href时,它始终只是主要位置,没有这个新零件,包括项目ID#id = 12345

Yes, you can create FB Like buttons for "items" shown on dynamically created screen content (eg Ajax popups). 是的,您可以为动态创建的屏幕内容(例如Ajax弹出窗口)上显示的“项目”创建FB Like按钮。

Issues: 问题:

Individual item urls FB demands a "social graph endpoint" for each item that can be liked. 单个项目网址 FB要求为每个喜欢的项目提供一个“社交图终点”。 So you also need to support a url which returns only the "item." 因此,您还需要支持仅返回“项目”的网址。 This is the url for the individual item. 这是单个项目的网址。 It is also the url that a FB viewer will click on if they want to find out more about the item. 如果他们想了解有关该项目的更多信息,它也是FB查看器将单击的URL。

Example: a page shows a list of articles. 示例:页面显示文章列表。 There is an individual Like button next to each article. 每篇文章旁边都有一个单独的“赞”按钮。 When a person "Likes" article B, it is shown in their FB stream. 当某人“喜欢”商品B时,该商品会显示在其FB流中。 When they click on "Article B" in the stream, it should go to a page that only shows article B. 当他们单击流中的“文章B”时,应该转到仅显示文章B的页面。

Also, the url for just article B will be queried by Facebook to obtain the FB meta headers for the individual item (image, classification, etc). 此外,Facebook将查询仅文章B的URL,以获得单个项目(图像,分类等)的FB元标题。

Parsing the new dom for FB items Depending on which method you use for adding FB like buttons et al, you may need to tell FB to explicitly (re-)parse the new parts of the dom that you just added dynamic content to. 解析FB项目的新dom取决于按钮等添加FB的方法,您可能需要告诉FB明确(重新)解析刚刚向其中添加动态内容的dom的新部分。 (Your pop-up.) (您的弹出窗口。)

Since you know the element that you added the popup to, there is no need to tell FB to reparse your entire dom. 由于您知道添加了弹出框的元素,因此无需告诉FB重新解析整个dom。 Tell them to parse starting at the beginning of your newly added/changed element: 告诉他们从新添加/更改的元素的开头开始进行解析:

Code I use: 我使用的代码:

if (event_data) { // event_data was received, show it
  panel.setBody(event_data); // set the pop-up's body
  if (!this.ie && typeof(FB) != "undefined" && FB.XFBML)
    {FB.XFBML.parse(this.panel_el);} // Parse FaceBook markup
....

Docs from FB on this: 来自FB的文档:

Place this in a for loop, and you should be fine. 将其放在for循环中,就可以了。

var elements = $("#divId").html();
$("#divId").html(elements + "like button code");
$("#divId.fb-like").attr("data-href", "what you want to link to");

See .html() and .attr() specs. 请参阅.html().attr()规范。

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

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