开发者

Graph API search pages and applications using php-sdk

开发者 https://www.devze.com 2023-04-10 08:59 出处:网络
I am looking for - Sample on how to use graph api search pages to get me started. Doe开发者_开发问答s the api include applications in the search?

I am looking for -

  • Sample on how to use graph api search pages to get me started.
  • Doe开发者_开发问答s the api include applications in the search?
  • Do i need an access token to use this feature, i did not see in the docs?


this sample assumes you have php-sdk 3.1.1 installed. and are using a form to submit the search to current page. 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.'';
    }
}


Here is what I've been doing with Ajax. Make a php file (fbAuth.php, in this example), first :

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);

And then, using 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
}
0

精彩评论

暂无评论...
验证码 换一张
取 消