facebook_graph_request

This function is used to interact with the Facebook social graph.

Syntax:

facebook_graph_request(graph_path, httpMethod, ds_map_parameters, ds_map_return)


Argument Description
graph_path The part of the social graph to interact with
httpMethod The http method to use (POST, GET, DELETE).
ds_map_parameters The ds_map with the information to send.
ds_map_return The ds_map to receive (-1 for none).


Returns: N/A


Description

With this function you can get the user to interact with the Facebook Social Graph. The "graph_path" argument is where you define the part of the graph you wish to access, like the current user friends list, or another apps comments or even an event. The exact path can be defined using the terms outlined in the Publishing section of the Facebook Graph Api pages. You then define the http method to use which is usually POST or GET but Facebook also accepts the DELETE method.

The next argument is slightly more complex as it requires you to have created and filled a ds_map with the correct information which GameMaker: Studio will then convert into json automatically when sent to the Facebook Api. The information that you put in this map will depend very much on which path you choose to use and a complete list of all possible values can be found here. An example of how this map is structured can be seen in the code example supplied below.

Finally, we have an argument for storing any information that Facebook has sent back from the graph request. This information comes in the form of json which GameMaker: Studio converts into a ds_map. For this to work correctly, you must have created a ds_map previously, and if that map has been used elsewhere and already contains some key/value pairs it will be cleared by this function before the Facebook data is added. It is very important that you read the Facebook documentation on possible return values so that you know exactly what to expect. Thankfully Facebook have a Graph Api Test Page where you can check different graph paths and see exactly what information they will return.

NOTE: The user must be logged in for the graph request to function.


Example:

var wallPostMap;
wallPostMap = ds_map_create();
ds_map_add(wallPostMap, "message", "I just got a hi-score playing Catch The Clown!");
ds_map_add(wallPostMap, "picture", "http://MacSweeneygames.com/Clown.jpg");
ds_map_add(wallPostMap, "link", "http://MacSweeneygames.com/");
ds_map_add(wallPostMap, "name", "Catch The Clown");
ds_map_add(wallPostMap, "caption", "MacSweeneygames.com");
ds_map_add(wallPostMap, "description", "Play Catch the clown now on MacSweeney Games!");
facebook_graph_request("me/feed", "POST", wallPostMap, -1);
ds_map_destroy(wallPostMap);

The above code will create a ds_map and store its index in the local variable "wallPostMap". It then fills the ds_map with the relevant key/value pairs that are needed to post an image and text to the currently logged in users wall. Finally it sends the graph request and deletes the ds_map from memory.


Back: Facebook
Next: facebook_dialog
© Copyright YoYo Games Ltd. 2018 All Rights Reserved