Facebook - How to get a list of friends

1

Index

Stats

8,723 visits, 17,115 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

How to request for a "Friend Photo URL"

The second function you will paste in (shown below) serves to retrieve the URL of a specific friend of the player. Copy it and paste it into runtime.js, just before the line which reads "pluginProto.acts = new Acts();" again.

Notice a variable "n" is passed to the function called RequestUserFriendURL on line 1. This is used in line 5 to GET the URL to the picture by making a call to FB.api. The callback function(response) saves the information in fbFriendURL in line 11, and then triggers a condition trigger in line 12.

    Acts.prototype.RequestUserFriendURL = function (n) {
       var responseLength = 0;
       if (this.runtime.isDomFree)
          return;
       FB.api('/' + fbFriendsID[n] + '/picture', 'GET', { "access_token": fbAppID + "|" + fbAppSecret }, function(response) {
          if (!response.data)
          {
             console.error("Friend URL failed: " + response);
             return;
          }
          fbFriendURL = response.data.url;
          fbRuntime.trigger(cr.plugins_.FacebookGW.prototype.cnds.OnFriendURLReceived, fbInst);
          if (!response || response.error) {
             console.error(response);
          } else {
             log(response);
          }
       });
    };

Because of line 11, we must declare the new variable in your code. Search for the following line "function onFBLogin()" in runtime.js and insert the following declaration in the code before the line.

    var fbFriendURL = "NO URL";

The trigger condition function is pasted before the following line "pluginProto.cnds = new Cnds();".

    Cnds.prototype.OnFriendURLReceived = function ()
    {
       return true;
    };

To retrieve the URL information, you insert in the following function before "pluginProto.exps = new Exps();".

    Exps.prototype.FriendURL = function (ret) {
       ret.set_string(fbFriendURL);
    };

OK, now save runtime.js and fire up edittime.js. Make the following changes to the relevant sections for Actions, Conditions, and Expressions.

    AddNumberParam("Index of Friend", "The Friend URL to retrieve.");

AddAction(13, 0, "Request friend URL", "Friends info (no permissions required)", "Request friend URL: <b>{0}</b>", "Request Request friend URL, triggering 'on friend URL available' when the info is received.", "RequestUserFriendURL");

    AddCondition(10, cf_trigger, "On Friend URL available", "On Friends Info available", "On Friends Info available", "Triggered after the 'RequestUserFriendURL' action.", "OnFriendURLReceived");

    AddExpression(17, ef_return_number, "Get Friend URL", "Facebook", "FriendURL", "Get the Friend URL requested earlier.");

  • 0 Comments

  • Order by
Want to leave a comment? Login or Register an account!