i'm new studying facebook api search. use code, resault empty. can me? thanks.
<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">
your $url parameter set to:
"https://graph.facebook.com/oauth/access_token?ient_id=api_id&redirect_uri=my_url&client_secret=my_secret";
the values 'client_id', 'redirect_uri', , 'client_secret' still set placeholders. best way handle so:
<? // params encoded in auth url $params = array( 'client_id' => $fb_app_id, 'redirect_uri' => $my_redirect_url, 'client_secret' => $fb_app_secret, ); // encode params in string $paramstring = "?"; foreach($params $key=>$value) { $paramstring .= "&{$key]=" . urlencode($value); } // auth url $url = "https://graph.facebook.com/oauth/access_token" . $paramstring;
you should assign real desired values $fb_app_id
, $my_redirect_url
, , $fb_app_secret.
for $fb_app_id
, $fb_app_secret
, can them app's settings in facebook developer area app in question (at http://www.facebook.com/developer).
the value of $my_redirect_url
has real url within 'web site' tab in edit app area: http://drktd.com/3zc4
Comments
Post a Comment