我有兩件事: - 怎麼做:使用PHP的Facebook的Facebook檢查,用戶喜歡我的應用程序?Facebook的PHP SDK - 用戶「喜歡」我的應用程序?
我需要這個,因爲客戶想要它。
$isLike = /* Code to check this */
if ($isLike){
//if user like my app
}else{
//if not
include 'generate.php';
}
而我應該問什麼「有效」英語這個問題?
我有兩件事: - 怎麼做:使用PHP的Facebook的Facebook檢查,用戶喜歡我的應用程序?Facebook的PHP SDK - 用戶「喜歡」我的應用程序?
我需要這個,因爲客戶想要它。
$isLike = /* Code to check this */
if ($isLike){
//if user like my app
}else{
//if not
include 'generate.php';
}
而我應該問什麼「有效」英語這個問題?
這裏有一個非常好的教程:http://thinkdiff.net/facebook/php-sdk-3-0-graph-api-base-facebook-connect-tutorial/這應該讓你瞭解SDK的速度。但是,它不談論喜歡。要做喜歡,你需要使用SDK調用圖API(https://developers.facebook.com/docs/reference/api/user/#likes)。該調用看起來像$facebook->api("/$user/likes");
遍歷喜歡列表以查看您的應用程序是否已列出。
要檢查用戶是否喜歡你的應用程序或者您有沒有實現從Facebook這樣的事用PHP SDK,並使用FB像按鈕,你的主文件,如index.php文件:
//Include your PHP FB SDK :
require 'facebook.php';
//Check user loggin or not with your code
try {
$facebook = new Facebook (array ('appId' => 'APP_ID', 'secret' => 'APP_SCRET', 'cookie' => true));
//Get current user ID
$user = $facebook->getUser();
//Get your app info
$appinfo = $facebook->api ("APP_ID");
**//This link will be parse to FB Like button URL to like**
$linkToLike = $appinfo ['link'];
//Check if current user liked your app or not
$likeInfo = $facebook->api ("$user/likes/APP_ID");
if ($likeInfo['data'] == null){
//User not yet liked your app, include page holding like button
include_once 'home.php';
}else{
echo 'You liked this application and now this is application info:'.'<br/>';
echo '<pre/>';
print_R ($likeInfo);
exit();
}
} catch (Exception $e) {
echo '<pre/>';
print_R ($e);
exit();
}
在家裏。 PHP你應該有這樣的像按鈕:
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
var APP_ID = 'APP_ID';
FB.init({
appId : APP_ID, // App ID
channelUrl : '//your_app_host_url/channel.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.Event.subscribe('edge.create', function(response) {
//user just clicked "like" on your page
alert('user just clicked Liked on your page');
//Do something here :)
});
FB.Event.subscribe('edge.remove', function(response) {
//user just clicked "unlike" on your page
alert('user just clicked "unlike" on your page');
//Do something here :)
});
};
</script>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=APP_ID";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-like" data-href="<?=$linkToLike?>" data-send="false"
data-layout="box_count" data-width="450" data-show-faces="false"></div>
希望幫助!
非常感謝你 – Szymad 2011-12-30 02:01:54
如果這回答了你的問題,你能標記這個答案接受?謝謝 :) – DMCS 2011-12-30 03:26:01