简体   繁体   English

Facebook Open Graph对象链接到Facebook App

[英]Facebook Open Graph Object Link to Facebook App

I'm building a Facebook canvas app which makes use of Open Graph. 我正在构建一个使用Open Graph的Facebook canvas应用。 So for example the app pulls in content from http://www.mysite.com/ Say the action posted to the timeline as "Duncan completed MyObject on My App " 因此,举例来说,该应用从http://www.mysite.com/提取了内容,并说该动作以“ Duncan在My App上完成了MyObject ”的形式发布到了时间轴上

Clicking My App opens the app page on Facebook. 单击我的应用程序可在Facebook上打开应用程序页面。 However clicking the MyObject link opens the actual page where all my meta data is added outside of Facebook www.mysite.com 但是,单击MyObject链接会打开实际页面,在该页面上我的所有元数据都添加到了Facebook www.mysite.com之外

I really just want both links to open the app in Facebook. 我真的只希望两个链接都可以在Facebook中打开该应用程序。 Am I missing a trick here or is my only solution to perform a redirect or something? 我是否在这里缺少技巧,还是我执行重定向或其他操作的唯一解决方案?

I understand I need to get Facebook to parse mysite.com in order to grab meta data. 我了解我需要让Facebook解析mysite.com才能获取元数据。 However, setting the og:url to the url of my app doesn't make a difference. 但是,将og:url设置为我的应用程序的URL并没有什么不同。

I was having the same issue. 我有同样的问题。 I ended up making a separate .jsp file which writes all the og: tags in the page, and in the body it only contains: 我最终制作了一个单独的.jsp文件,该文件在页面中写入了所有og:标记,在主体中仅包含:

<script>
    location.href = "<%=redirectUrl%>";
</script>

The redirectUrl variable is a String I calculate from the original requested URL, it is like "http://apps.facebook.com/xxxyyy?myParam=zzz". redirectUrl变量是我从原始请求的URL计算得出的字符串,就像“ http://apps.facebook.com/xxxyyy?myParam=zzz”。 Of course it can be anything, and in PHP or whatever language you use. 当然可以是任何东西,可以是PHP或您使用的任何语言。

When you post an action to Open Graph, use the page with the redirect as the object URL. 当您将操作发布到“打开图”时,请使用带有重定向的页面作为对象URL。 Facebook will parse the og tags nicely, and when an actual browser reads the page, it will redirect the user to your Facebook app. Facebook会很好地解析og标签,并且当实际的浏览器读取页面时,它将把用户重定向到您的Facebook应用。

I had the same problem, not sure if I was missing something really obvious. 我遇到了同样的问题,不确定是否遗漏了一些明显的东西。

I had a PHP file that followed the example file from Facebook. 我有一个PHP文件,该文件紧随Facebook的示例文件。 But when clicking the object on the timeline story, I noticed the following GET parameter: fb_source=timeline_og 但是,当单击时间轴故事中的对象时,我注意到以下GET参数: fb_source=timeline_og

So to solve the redirecting issue, I put the following at the top of the file, just inside the PHP tags: 因此,为解决重定向问题,我将以下内容放在文件顶部的PHP标记内:

<?php
    if ($_GET['fb_source'] == 'timeline_og') {
        // clicked on link in timeline, so redirect to required URL
        header('Location: REDIRECT_URL_HERE');
    }

(Obviously, replace REDIRECT_URL_HERE with whatever URL you wish to redirect to.) (显然,将REDIRECT_URL_HERE替换为您希望重定向到的URL。)

Hopefully someone will find this useful! 希望有人会发现这个有用!

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

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