English 中文(简体)
利用PHP SDK搜索F
原标题:Search Facebook using PHP SDK

在过去的几天里,我就在Facebook上需要搜索用户的申请开展了工作。 由于FQL查询,我决定使用共同搜索预报软件。

我使用PHP,即FB PHP SDK是我更喜欢的方式。 我以前曾用过这个词来回答QL的问题。

// $api is already initialized, with access_key, app secret and so on
$users = $api(array(
     method  =>  fql.query ,
     query  => "SELECT first_name,last_name FROM user WHERE uid= 12345 ",
));

我愿以类似方式建立查询系统。 尤其是,我不想code缩地标出参数,具体说明进入钥匙、秘密以及科索沃民主党本应为我做的所有工作。 然而,我没有能够利用SDK来建立这一询问。 是否有这样做的可能性? 如果是,如何? 我已经找到了得到 s支持的“电话”清单很长,但我需要打造图表。

Thanks in advance.


EDIT: To make it clear, I don t want to build the string by myself. I know this solution works. But imho it s ugly when I have SDK:

$name = urlencode(trim($first_name . " " . $last_name_));
$users = $this->facebook->api("/search?q=$name&type=user&access_token=$key");
问题回答

利用php-sdk 3.1.1通过图表搜索用户

  • User will need to authorize your app before making a search for users.

{
   "error": {
      "message": "A user access token is required to request this resource.",
      "type": "OAuthException"
   }
}

  • Php-skd 3.1.1 init.

<?php 
require  ./src/facebook.php ;
$facebook = new Facebook(array(
   appId   =>  your-app-id ,
   secret  =>  your-app-secret ,
));
$user = $facebook->getUser();
if ($user) {
  try {
    // Proceed knowing you have a logged in user who s authenticated.
    $user_profile = $facebook->api( /me );
  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
}

/*  */
if ($user) {
  $logoutUrl = $facebook->getLogoutUrl();
} else {
  $loginUrl = $facebook->getLoginUrl();
}
?>

  • Search includes, encoding search term, setting results limit, and offset for paging.

    <?php 
    /* Get Search parameter from url or post and urlencode it. */
$q = urlencode($_GET[ qs ]);
if(!$_GET[ qs ]){
$q = urlencode($_POST[ qs ]);
    if(!$_POST[ qs ]){
            /* Default Search Term */
    $q = "Shawn+E+Carter";
    }
}
    /* Get Results Limit from url or set default. */
$limit = $_GET[ limit ];
    if (!$_GET[ limit ]){
$limit = 60;
    }
    /* Get Offset from url or set default for paging. */
$offset = $_GET[ offset ];
    if (!$_GET[ offset ]){
$offset = 0;
}
    /* Make Graph API call to user */
$usersearch =  search%3Fq= .$q. %26type=user%26limit= .$limit. %26offset= .$offset.  ;

    echo  <pre style="text-align: left;"> ;
    print_r($usersearch);
    echo  </pre> ;
    ?>




相关问题
Search field with Thickbox issue

i have a search form which is shown with Thickbox inside an iframe. the problem is.. that after i click "search" the result page is shown inside the same iframe! and i want it to be shown in the main ...

Will an incomplete google sitemap hurt my search ranking?

If I submit a sitemap.xml which does not contain all of the pages of my site, will this affect my search ranking? For example: If my sitemap only contained pages that had been created in the last ...

speeding up windows file search with C#

i made a program that search logical drives to find a specific file .if user type file name an click search button , searching begins , but i don t know how to stop searching in the middle of process....

JQuery/MVC Search Issue

I have inherited a piece of work where the entry screen shows a summary of 20 calculated variables. E.g. Var A (250), Var B (79). Clicking on any of these links takes the user to a view with a ...

Handling no results for docmd.applyfilter

I have an Access app where I use search functionality. I have a TextBox and a Search Button on the form, and it does a wildcard search of whatever the user enters in the TextBox, and displays the ...

Search by using the keyboard in a list/grid - algorithm

I need to implement a custom search in a grid and I would like to find some user interface guidelines that explain the standard way to implement it. I mean this kind of search that is initiated by ...

Embed Google/ Yahoo search into a web site or build your own

I am looking for an opinion on the whether to use Google custom search, Yahoo search builder or build my own for web projects (no more than 100 pages of content). If I should build my own - do you ...

热门标签