4

I have the following code that would get ur friends list using graph api

function getFriendsList(){

    $response = $this->api('/me/friends'); 
     return $response;

    }

This returns friends id and name. using graph api

I then execute this code in my joomla module:

$fbClient = JFBConnectFacebookLibrary::getInstance();
$fbUserId = $fbClient->getUserId(TRUE);   

//If FB User
if($fbUserId){

$f_list = $fbClient->getFriendsList();

after i get the array i display the firends picture

foreach ($f_list as $friend) {
    for($i = 0; $i < count($friend); $i++)
        { 

        echo '<img src="http://graph.facebook.com/'.$friend[$i]['id'].'/picture"><br/>';
        }
   }

}

This would create the profile photos of my friends.

My question is how do i create an onlick even so that when i click the photo i can send an individual facebook app request. ???

Somnath Muluk
  • 55,015
  • 38
  • 216
  • 226
ivias
  • 249
  • 1
  • 3
  • 15

2 Answers2

6

Sending Facebook app requests are not available via the graph api. You can use the app requests javascript dialog to send the request though, you would just need to specify the user's id in the "to" property as detailed in the documentation.

Sample function:

<script>
  FB.init({ appId: '**appId**', status: true, cookie: true, xfbml : true });

  function sendRequest(to) {
    FB.ui({method: 'apprequests', to: to, message: 'You should learn more about this awesome site.', data: 'tracking information for the user'});
    return false;
  }
</script>

Then just wire an onclick for each image to something like onclick="return sendRequest('**friendId**');"

bkaid
  • 51,465
  • 22
  • 112
  • 128
  • c is null [Break On This Error] FB.provide('Dom',{containsCss:function...(oldonload);}else oldonload();};})(); – ivias Sep 10 '11 at 00:20
  • I am not expert on Facebook, but reading thru this article http://developers.facebook.com/blog/post/464/ it says that you can send an app request using the PHP API. The article is older than this post so it may be outdated. Do you know if its possible? Thanks – Daniel Benedykt Oct 19 '11 at 20:16
  • 9
    You can't send app requests from one user inviting another user via the graph api. Developers would spam that and invite every single friend on their list once the user approves the app. You are referring to app-generated requests, and those are available as you mention. – bkaid Oct 19 '11 at 20:19
5

I had same problem. Though it is very late for answering question, it will help somebody. That's why answering this question.

Instead you can call this function in javascript: it will give you all friends with photos. Also group of friends who are currently using same app. You can send request to any of them.

function sendRequestViaMultiFriendSelector() {
    FB.ui({
        method: 'apprequests',
        message: "You should learn more about this awesome site."
    });     
}
Somnath Muluk
  • 55,015
  • 38
  • 216
  • 226