Dan
Dan

Reputation: 2174

How to get the sender id from facebook

Say I'm A. And A sends invite to B. When B ,accepts my friend request,then i am geting request id on my page but how do i get A UID of Mine(A) on my php page?

Please help me. Am struggling since 6 hrs for this.

I am using these(see below) code for getting request_Id. But from these How can i get the SENDERS ID?

 <?php
    require_once('phps/fbsdk/src/facebook.php');
    $config = array
    (
      'appId' => '27c3932323897****82',
      'secret' => '******************************',
    );
    $facebook = new Facebook($config);
    //get the request ids from the query parameter
     $request_ids = explode(',', $_REQUEST['request_ids']);

     //build the full_request_id from request_id and user_id
      function build_full_request_id($request_id, $user_id) {
      return $request_id . '_' . $user_id;
     }

     //for each request_id, build the full_request_id and delete request
     foreach ($request_ids as $request_id)
     {
     echo ("reqeust_id=".$request_id."<br>");
     $full_request_id = build_full_request_id($request_id, $user_id);
     echo ("full_request_id=".$full_request_id."<br>");

    try {
     $delete_success = $facebook->api("/$full_request_id",'DELETE');
     if ($delete_success) {
        echo "Successfully deleted " . $full_request_id;}
     else {
       echo "Delete failed".$full_request_id;}
    }
    catch (FacebookApiException $e) {
    echo "error";}
    }
 ?>`

Upvotes: 4

Views: 2098

Answers (1)

derki
derki

Reputation: 620

Make a call to graph api (graph.facebook.com/{REQUEST_ID}) using request id you get, you will receive sender ID, you will get something like this:

{
  "id": "493703870648580", 
  "application": {
    "name": "Send Requests How To", 
    "id": "403223126407920"
  }, 
  "to": {
    "name": "Chris Abe Colm", 
    "id": "100003086810435"
  }, 
  "from": {
    "name": "Christine Abernathy", 
    "id": "1424840234"
  }, 
  "data": "{\"badge_of_awesomeness\":\"1\",\"social_karma\":\"5\"}", 
  "message": "Learn how to make your Android apps social", 
  "created_time": "2012-10-07T17:29:57+0000"
}

more about graph api: http://developers.facebook.com/docs/reference/api/

PS: remove your app secret from your sample

Upvotes: 3

Related Questions