FB iframe选项卡 - 如果页面不是“喜欢”,则隐藏/更改内容 [英] FB iframe tab - hide/alter contents if page is not "liked"

查看:119
本文介绍了FB iframe选项卡 - 如果页面不是“喜欢”,则隐藏/更改内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是怎么做到的?我看到一些隐藏的iframe内容 - 在这种情况下,一个图形向上,并说出一些像我们这样的 - 或者一个报价 - 例如,如果页面是喜欢。



我已经挖了这个,但没有任何运气。已经完成了,但我没有预见到哪些FB页面正在做... .... argh!

解决方案

为了实现这一点,您将需要一个Facebook应用程序。一旦设置完毕,创建页面,页面加载时,用户将需要授权您的应用程序,以便您可以访问他们的个人信息,以查看他们是否喜欢使用某些FQL的页面。以下代码将检查Facebook用户是否喜欢该页面,但只有在用户允许访问您的应用程序的情况下才会运行。

 < div id =fb-root>< / div> 
< script src =http://connect.facebook.net/en_US/all.js>< / script>
< script>
FB.init({
appId:'yourAppId',
status:true,
cookie:true,
xfbml:true
});
FB.getLoginStatus(function(response){
if(response.session){
var user_id = response.session.uid;
var page_id =xxxx; //您想要的页面
var the_query = FB.Data.query(SELECT uid FROM page_fan WHERE page_id = {0} and uid = {1},page_id,user_id);
the_query。 wait(function(rows){
if(rows.length == 1&& rows [0] .uid == user_id){
$(#divWhenLiked)。
} else {
$(#divWhenNotLiked)。show();
}
});
} else {
// user is没有登录
$(#divNoPermission)。show();
}
});
< / script>

在代码中,您将看到3 < div> 标签将显示取决于用户是否允许您的应用程序,不喜欢的页面,并喜欢的页面。在显示权限的< div> 标签中,为了使其正常工作,您需要一个链接到您的应用程序的超链接,例如: / p>

  http://www.facebook.com/dialog/oauth?client_id=yourAppId&redirect_uri=http://yourWebsite/yourRedirectPage 

这将从Facebook显示一个弹出窗口,要求用户允许应用程序的权限。然后,它将重定向到您在链接中指定的重定向页面。在您的RedirectPage中,您只需要在< body> 标签中的简单重定向代码片段:

 <脚本> 
window.location.href =http://www.facebook.com/pages/YourApp?sk=app_yourAppId;
< / script>

您可以从Facebook应用页面获取超链接。希望这有帮助。


How is this done? I've seen some iframe content which was either hidden - in which case a graphic pointing up and saying something to the effect of "like us..." - or an offer - for example a discount available to the viewer if the page is "liked".

I've dug around for this, but haven't had any luck. It's been done, but I didn't have the foresight to note which FB pages were doing it.... argh!

解决方案

You will need a Facebook application in order to achieve this. Once you have set that up, create your page and when the page loads, the user will need to authorise your application so that you can get access to their personal information to see whether they like the page using some FQL. The code below will check to see if a Facebook User likes the page, but this will only run if a user has allowed access to your application.

<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
    FB.init({
        appId : 'yourAppId',
        status: true,
        cookie: true,
        xfbml : true
    });
    FB.getLoginStatus(function(response) {
        if (response.session) {
            var user_id = response.session.uid;          
            var page_id = "xxxx"; //The Page that you want to Like
            var the_query = FB.Data.query("SELECT uid FROM page_fan WHERE page_id = {0} and uid={1}", page_id, user_id);          
            the_query.wait(function(rows) {              
                  if (rows.length == 1 && rows[0].uid == user_id) {                 
                     $("#divWhenLiked").show();         
                  } else {                  
                     $("#divWhenNotLiked").show();
                  }          
            });      
        } else {        
            // user is not logged in   
            $("#divNoPermission").show();               
        }    
    });
</script>

In the code, you'll see 3 <div> tags which will be shown dependant on whether the user has allowed your application, not Liked the page, and Liked the page. In the <div> tag that shows the permissions, in order to get this to work you'll need a hyperlink that will link off to your application, for example:

http://www.facebook.com/dialog/oauth?client_id=yourAppId&redirect_uri=http://yourWebsite/yourRedirectPage

This will display a Pop-up window from Facebook asking for the user to allow permission to the application. It will then redirect to your Redirect Page that you have specifed in the link. In your RedirectPage, you'll just need a simple redirect piece of code in the <body> tag:

<script>
window.location.href = "http://www.facebook.com/pages/YourApp?sk=app_yourAppId";
</script>

You can get the hyperlink from the Facebook application page. Hope this helps.

这篇关于FB iframe选项卡 - 如果页面不是“喜欢”,则隐藏/更改内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆