我正在寻找 -
答案 0 :(得分:3)
此示例假设您已安装php-sdk 3.1.1。并使用表单将搜索提交到当前页面。 url format sample.com/?qs=search+facebook
$q = urlencode($_GET['qs']);
if(!$_GET['qs']){
$q = urlencode($_POST['qs']);
if(!$_POST['qs']){
$q = "facebook";
}
}
$MEsearch = $facebook->api('/search?q='.$q.'&type=page&limit=100');
foreach ($MEsearch as $key=>$value) {
foreach ($value as $fkey=>$fvalue) {
$pagename = $fvalue[name];
$pageid = $fvalue[id];
$pagecategory = $fvalue[category];
echo ''.$pagename.' '.$pagecategory.'';
}
}
答案 1 :(得分:1)
以下是我用Ajax做的事情。首先制作一个php文件(在本例中为fbAuth.php):
require_once("fb_sdk/src/facebook.php"); //Path to FB SDK
$facebook = new Facebook(array(
'appId' => 'yourappid',
'secret' => 'yourappsecret',
));
$query = urlencode('searchterm');
$type = 'post';
$ret = $facebook->api('/search?q='.$query.'&type='.$type);
echo json_encode($ret);
然后,使用jQuery:
function fb_fetchPosts(){
$.ajax({
url: "fbAuth.php",
type: "POST",
datatype: "json",
success: fb_success
});
}
function fb_success(posts){
posts = $.parseJSON(posts);
//Do stuff here
}