Facebook如何检查用户是否喜欢页面并显示内容?

我正在尝试创建一个Facebook iFrame应用。该应用程序应首先显示图像,如果用户喜欢该页面,则可以访问某些内容。


我使用RoR,因此无法使用Facebook PhP SDK。


当用户不喜欢该页面时,这是我的iFrame HTML:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

<head>

<link rel="stylesheet" type="text/css" href="style.css" />

<style type="text/css">

body {

width:520px;

margin:0; padding:0; border:0;

font-family: verdana;

background:url(repeat.png) repeat;

margin-bottom:10px;

}

p, h1 {width:450px; margin-left:50px; color:#FFF;}

p {font-size:11px;}

</style>

<meta http-equiv="Content-Type" content="text/html;

charset=iso-8859-1" />

</head>

<body>

<div id="container">

<img src="welcome.png" alt="Frontimg">

</div>

并且,如果用户喜欢该页面:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

<head>

<link rel="stylesheet" type="text/css" href="style.css" />

<style type="text/css">

body {

width:520px;

margin:0; padding:0; border:0;

font-family: verdana;

background:url(repeat.png) repeat;

margin-bottom:10px;

}

p, h1 {width:450px; margin-left:50px; color:#FFF;}

p {font-size:11px;}

</style>

<meta http-equiv="Content-Type" content="text/html;

charset=iso-8859-1" />

</head>

<body>

<div id="container">

<img src="member.png" alt="Frontimg">

<p>You liked this page</p>


一只甜甜圈
浏览 530回答 3
3回答

ibeautiful

您需要编写一些PHP代码。当用户第一次单击选项卡时,您可以检查他是否喜欢该页面。下面是示例代码include_once("facebook.php");&nbsp; &nbsp; // Create our Application instance.&nbsp; &nbsp; $facebook = new Facebook(array(&nbsp; &nbsp; &nbsp; 'appId'&nbsp; => FACEBOOK_APP_ID,&nbsp; &nbsp; &nbsp; 'secret' => FACEBOOK_SECRET,&nbsp; &nbsp; &nbsp; 'cookie' => true,&nbsp; &nbsp; ));$signed_request = $facebook->getSignedRequest();// Return you the Page like status$like_status = $signed_request["page"]["liked"];if($like_status){&nbsp; &nbsp; echo 'User Liked the page';&nbsp; &nbsp; // Place some content you wanna show to user}else{&nbsp; &nbsp; echo 'User do not liked the page';&nbsp; &nbsp; // Place some content that encourage user to like the page}
打开App,查看更多内容
随时随地看视频慕课网APP