Using facebook sdk to show ALL mutual friends, not just those with the app?
4 answers
The additional notes on this page explain it pretty well why you can't get everything.
- A valid user access token with user_friends permission is required to view other friends' mutual friends using the app.
- The user in the request and the session user must grant the user user access rights.
- Also, the answer will only include mutual friends that have given users user_friends.
That is, the only way to get a complete list of mutual friends is if all your friends have joined your app and have granted user_friends permissions
+4
source to share
What is the end point for all friends:
https://developers.facebook.com/docs/graph-api/reference/v2.5/user-context/all_mutual_friends
Returns a list of all Facebook friends that have session user and request user. This includes friends who are using the app as well as friends who are not using the app.
It also says that you must request this endpoint from your server, not the application client.
+1
source to share
function aa_mutl_frnd(x, row)
{
FB.init({
appId : '<?php echo get_option('_fb_apps_id');?>', //Facebook apps id using theme option
cookie : true, // enable cookies to allow the server to access
// the session
xfbml : true, // parse social plugins on this page
version : 'v2.5' // use graph api version 2.5
});
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
var accessToken = response.authResponse.accessToken;
console.log(':acc_tk:'+accessToken);
//////////////////////////////////////////////////////////
var data={
'action': 'wq_accss_tkn_gnrt',
'ddt' : accessToken
}
$.post('<?php echo admin_url('admin-ajax.php'); ?>', data, function (response) {
console.log(':acc_tk2:'+response);
FB.api(
"/"+x+"",
{
"fields": "context.fields(all_mutual_friends)",
//"access_token": '',
"appsecret_proof": response,
},
function (response) {
console.log(response);
}
);
});
////////////////////////////////////
}
});
}
/// ajax part /////
add_action('wp_ajax_wq_accss_tkn_gnrt', 'wq_accss_tkn_gnrt');
add_action('wp_ajax_nopriv_wq_accss_tkn_gnrt', 'wq_accss_tkn_gnrt');
function wq_accss_tkn_gnrt() {
echo hash_hmac('sha256',$_POST['ddt'],'app_secret');;
die();
}
+1
source to share
get facebook friends
$access_token = "facebook token";
$app_secret = "facebook secret";
$appsecret_proof = hash_hmac('sha256', $access_token,
$app_secret);
$graph_url = "https://graph.facebook.com/me?fields=context.fields(/me?fields=id,name,friends.limit(99)" . "&access_token=" . $access_token . "&appsecret_proof=" . $appsecret_proof;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $graph_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$output = curl_exec($ch);
return $response_mutual = json_decode($output, true);
curl_close($ch);
0
source to share