Facebook api search.

I am new to learning Facebook searches. I use this code, but the reset is empty. Can someone help me? Thank.

<form action ="index.php" method ="post">
<input type="text" value="what is?" name="search" style="color:#999;text-align:center;" onfocus="if (value =='what is?'){value =''}" onblur="if (value ==''){value='what is?'}"/>
<input type ="submit" value="ok" />
</form>
<?php
function callFb($url)
{
    $ch = curl_init();
    curl_setopt_array($ch, array(
        CURLOPT_URL => $url,
        CURLOPT_RETURNTRANSFER => true
    ));

    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
}

$url = "https://graph.facebook.com/oauth/access_token?client_id=api_id&redirect_uri=my_url&client_secret=my_secret";
$access_token = callFb($url);
$access_token = substr($access_token, strpos($access_token, "=")+1, strlen($access_token));

$url1 = "https://graph.facebook.com/search?access_token=".$access_token."&q=".urlencode($_POST['search'])."&type=user";
$ret_json = callFb($url1);
$users = json_decode($ret_json, true);

?>

<img src="https://graph.facebook.com/<? echo $users[data][0][id]; ?>/picture?type=small">
+3
source share
2 answers

The $ url parameter has a value:

"https://graph.facebook.com/oauth/access_token?ient_id=api_id&redirect_uri=my_url&client_secret=my_secret";

The values ​​for client_id, redirect_uri, and client_secret are still set to placeholders. The best way to handle this:

<?

// params to be encoded in the auth URL
$params = array(
    'client_id' => $fb_app_id,
    'redirect_uri' => $my_redirect_url,
    'client_secret' => $fb_app_secret,
);

// encode the params in to a string
$paramString = "?";
foreach($params as $key=>$value) {
    $paramString .= "&{$key]=" . urlencode($value);
}

// auth URL
$url = "https://graph.facebook.com/oauth/access_token" . $paramString;

You must assign the actual required values $fb_app_id, $my_redirect_urland $ fb_app_secret.

$fb_app_id $fb_app_secret Facebook Developer (http://www.facebook.com/developer).

$my_redirect_url URL- "-" " ": http://drktd.com/3zc4

+4

, nil null

https://graph.facebook.com/search?q=mark&type=user&access_token=<%=your token%>

{
   "data": [
      {
         "name": "Mark Maglasang",
         "id": "142137849672813"
      },
      {
         "name": "Mark Daniel",
         "id": "137983696724314"
      },
      {
         "name": "Mark Zuckerberg",
         "id": "10101640953722381"
      },
      {
         "name": "Mujeres Del Markham Desnudas",
         "id": "1046548842073860"
      },
      {
         "name": "Mark Tarello",
         "id": "10153122965377699"
      },
      {
         "name": "Mark Feister",
         "id": "128516701078456"
      },
      {
         "name": "Mark Connors",
         "id": "828042037238121"
      },
      {
         "name": "Mark Schonbach",
         "id": "10102125662137944"
      },
      {
         "name": "Gift Mark",
         "id": "276086699535224"
      },
0

Source: https://habr.com/ru/post/1781239/


All Articles