Comunidad Game Maker

Ayuda => Preguntas y respuestas => Mensaje iniciado por: josema88 en Julio 31, 2014, 06:14:25 PM

Título: Facebook login Failed
Publicado por: josema88 en Julio 31, 2014, 06:14:25 PM
Buenas tardes.
Llevo bastante tiempo dándole vueltas y no veo cual es el error  :-X
El caso es q el login de facebook siempre me da FAILED.
Agradecería mucho una ayuda  ;)

Este es mi código



script_globals

facebook_init(); 
global.Auth = false; //use for the facebook code
global.current_username = "Offline"; //facebook name of the logged in user from facebook
global.facebook_app_id = "256567984522198";  //Make sure to put your facebook app id here. If you dont know how make sure to do the facebook tur. in GM

string_insert_separator

// string_insert_separator(str, sep, n)

// Returns with a string where the given separator have been

// inserted after every nth character, from right to left.

//Example:string_insert_separator("10040394", ",", 3)
//Will Returne Will draw 10,040,394

var str, sep, n, l, a;

str = string(argument0)

sep = argument1

n = argument2

l = string_length(str) - 1

for (a = 0 a < floor(l / n) a += 1) str = string_insert(sep, str, l + 2 - n * (a + 1))

return str


obj_int create event

//ok here we will load the globals and then go to the main room
script_globals();
   

onj_button_facebook_sign_in left released event

if global.Auth
{
//ok user wants to sign out
facebook_logout();
global.Auth = false;
global.current_username = "Offline";
global.current_id = "";
}
else
{
//ok user wants to sign in
instance_create(0, 0, obj_facebook_login);
}


onj_button_facebook_sign_in draw event

draw_set_halign(fa_center);
draw_set_color(c_yellow);
draw_set_font(font1);

/*
Ok here we draw the button if they are singed in or not.
We also draw their facebook name and the status of facebook login
And we are drawing it around the sign in button
*/

if global.Auth
{
    draw_sprite(spr_button_facebook_sign_out, image_index, self.x, self.y);
}
else
{
    draw_sprite(spr_button_facebook_sign_in, image_index, self.x, self.y);
}

draw_text(400,(self.y - 65),"Player: " + string(global.current_username))
draw_text(400,(self.y + 35),"FB Status: "+string(facebook_status()))


obj_facebook_login create event

//need to set permissions for the login here
if os_is_network_connected()
    {
permissions = ds_list_create();                     // A ds_list to hold all possible permissions. MUST be used, even if no permissions are to be sent
ds_list_add(permissions,"publish_actions");          // Add the permissions to the list. If no permissions are necessary this is not necessary
facebook_login(permissions);
alarm[0] = room_speed;
}


obj_facebook_login destroy event

ds_list_destroy(permissions);       // Remove the ds_list from memory


obj_facebook_login alarm 0 event

//Check the Facebook status and set a global variable
var fbStatus;
fbStatus = facebook_status();                                       // Get the Facebook status

switch (fbStatus)                                         
{
case "AUTHORISED":                                                  //Facebook authorised!
    global.Auth = true;
    instance_destroy();
    break;   
case "IDLE":                                                        //facebook initialised - ready to login 
    global.Auth = false;
    alarm[0] = 30;
    break;   
case "FAILED":                                                      //Failure in the connection, so try again...
    global.Auth = false;
    alarm[0] = 30;
    break;   
case "DENIED":                                                      //We have not granted permissions to our facebook app
    global.Auth = false;
    instance_destroy();                                         //Denied, probably because the user as not given permission.
    break;
   
default: alarm[0] = 30;                                             //None of the above options, so repeat the alarm until we have a result
}



obj_facebook_get_name create event

mFacebookResponse = ds_map_create(); // Prepare for the Facebook response

//ok lets get their face book name
if global.Auth
{
facebook_graph_request("me", "GET", -1, mFacebookResponse); // Use the graph request as an http GET with the user id
alarm[0] = room_speed;
}


obj_facebook_get_name destroy event

ds_map_destroy(mFacebookResponse);      // Destroy the ds_map



obj_facebook_get_name alarm 0 event

/*
OK we got a responce from face book, lets loop through the data and get their name
*/

alarm[0] = room_speed;
if global.Auth                                                                              // Check to see of authorised
{
var currentKey, currentValue, currentValue2;                                           // Prepare local vars

currentKey = ds_map_find_first(mFacebookResponse);
if ds_map_exists(mFacebookResponse, currentKey)
    {
    currentValue = ds_map_find_value(mFacebookResponse, "name");                       
    global.current_username = string(currentValue);
   
    //you can use the code below to get the facebook id if you need it
   
    //currentValue2 = ds_map_find_value(mFacebookResponse, "id");
    //global.current_id = string(currentValue2);
   
    instance_destroy();

    }
}



obj_facebook_highscores create event

/*
Ok we are going to use a grid to draw out high score table.
First lets create it and set the defaults.
*/

bGotResponce = false;
graphResponse = ds_map_create();        // Prepare a ds_map to receive information

    global.name_grid=ds_grid_create(1,10) //creates a grid for names
    ds_grid_set(global.name_grid,0,0,"nobody")
    ds_grid_set(global.name_grid,0,1,"nobody")
    ds_grid_set(global.name_grid,0,2,"nobody")
    ds_grid_set(global.name_grid,0,3,"nobody")
    ds_grid_set(global.name_grid,0,4,"nobody")
    ds_grid_set(global.name_grid,0,5,"nobody")
    ds_grid_set(global.name_grid,0,6,"nobody")
    ds_grid_set(global.name_grid,0,7,"nobody")
    ds_grid_set(global.name_grid,0,8,"nobody")
    ds_grid_set(global.name_grid,0,9,"nobody")
   
    global.score_grid=ds_grid_create(1,10) //creates a grid for scores
    ds_grid_set(global.score_grid,0,0,0)
    ds_grid_set(global.score_grid,0,1,0)
    ds_grid_set(global.score_grid,0,2,0)
    ds_grid_set(global.score_grid,0,3,0)
    ds_grid_set(global.score_grid,0,4,0)
    ds_grid_set(global.score_grid,0,5,0)
    ds_grid_set(global.score_grid,0,6,0)
    ds_grid_set(global.score_grid,0,7,0)
    ds_grid_set(global.score_grid,0,8,0)
    ds_grid_set(global.score_grid,0,9,0)
   
alarm[1] = room_speed / 2;



obj_facebook_highscores destroy event

//we looped through multiple lists, lets clean them all up

ds_grid_destroy(global.name_grid);
ds_grid_destroy(global.score_grid);

if (ds_map_exists(graphResponse, "data"))                               // Check to see if the ds_map exists
{
var dataList, dataListSize, n, friendMap, friendMap2, currentKey, currentValue;                               // Create local vars

dataList = ds_map_find_value(graphResponse, "data");                    // Get list
dataListSize = ds_list_size(dataList);                                  // Get list size

for (n = 0; n < dataListSize; n += 1)                                   // Start loop
    {
    friendMap = ds_list_find_value(dataList, n);                        // Get map
        currentKey = ds_map_find_first(friendMap);                                                  // Gets the first friend key (id)
        while (ds_map_exists(friendMap, currentKey))                                                // loop through the list, getting each ds_map
            {
            currentValue = ds_map_find_value(friendMap, currentKey);                               
            if string(currentKey) == "user"
            {
                ds_map_destroy(currentValue);
            }
            if string(currentKey) == "application"
            {
                ds_map_destroy(currentValue);
            }

            currentKey = ds_map_find_next(friendMap, currentKey);                                   // Get the next ds_map id key
           
            }
    ds_map_destroy(friendMap);                                          // Destroy map
    }   
ds_list_destroy(dataList);                                              // Destroy list
ds_map_destroy(graphResponse);                                          // Destroy main graph map
}



obj_facebook_highscores alarm 0 event

/*
Here we wait for our responce and then loop though the results and add them to the grid to draw
Right now we cant pull their profile pictures because GM doesnt support jpeg, yet.
Once GM supports jpg again we can pull the id of each user and use that to pull their profile picture.
When that happens I wll update this demo to pull the profile pics.
*/

if global.Auth
{
// If we've got a response to our friends list request then display it please

if (ds_map_exists(graphResponse, "data"))                                                           // Make sure that the map exists
    {
    var dataList, dataListSize, n, namenum, scorenum,  friendMap, friendMap2, currentKey, currentValue;                             // Set up local vars
namenum = 0;
scorenum = 0;
    dataList = ds_map_find_value(graphResponse, "data");                                            // Get the "data" list from the map
    dataListSize = ds_list_size(dataList);                                                          // Get the size of the data list
bGotResponce = true;
    for (n = 0; n < dataListSize; n += 1)                                                           // Loop through the list to get the names
        {

        friendMap = ds_list_find_value(dataList, n);                                                // Gets the ds_map from the list (this is the id/friend map)
        currentKey = ds_map_find_first(friendMap);                                                  // Gets the first friend key (id)
        while (ds_map_exists(friendMap, currentKey))                                                // loop through the list, getting each ds_map
            {
            currentValue = ds_map_find_value(friendMap, currentKey);                                // Get the friend that corresponds to the id
            if namenum <=9
            {
            if string(currentKey) == "user"
            {
                friendMap2 = ds_map_find_value(currentValue,"name");
                ds_grid_set(global.name_grid,0,namenum,string(friendMap2))
                namenum = namenum + 1;

            }
            if string(currentKey) == "score"
            {
               ds_grid_set(global.score_grid,0,scorenum,string_insert_separator(string(currentValue), ",", 3))
               scorenum = scorenum + 1;
            }
            }
           
            currentKey = ds_map_find_next(friendMap, currentKey);                                   // Get the next ds_map id key
                                                                         
            }
        }
    }
}

if !bGotResponce //no responce yet, keep waiting
{
alarm[0] = room_speed / 2;
}



obj_facebook_highscores alarm 1 event

//here we send the request to facebook, we use the facebook id and not the "me"
//once we are connected stop this alarm
if global.Auth
{
facebook_graph_request(string(global.facebook_app_id) + "/scores?limit=10", "GET", -1, graphResponse);             // Request information from Facebook
alarm[0] = room_speed / 2;
alarm[1] = -1;
}
else
{
alarm[1] = room_speed / 2;
}



obj_facebook_highscores draw event

// here we draw all the text in the room, including the grid




draw_set_font(font1);

if !global.Auth
{
draw_set_color(c_purple);
draw_set_halign(fa_center);
draw_text(400, 15, "Please Sign Into Facebook To View Top 10 Friends Highscores");
}

draw_set_color(c_black)
draw_set_halign(fa_center)
draw_text(400,50,"Top 10 Friends Highscores")
draw_set_halign(fa_left)

//draws the number order (1,2,3 etc.)
limit = 0
while limit < 10
{
    draw_text(260,85+(24*limit),string(1+limit)+".")
    limit+=1
}

//draws the names
a=0
while a < 10
{
    draw_text(375,85+(24*a),ds_grid_get(global.name_grid,0,a))
    a+=1
}

//draws the scores
draw_set_halign(fa_right)
//draw_text(510,130,"Score")
i=0
while i < 10
{
    draw_text(540,85+(24*i),ds_grid_get(global.score_grid,0,i))
    i+=1
}



Título: Re:Facebook login Failed
Publicado por: vitito93 en Enero 06, 2015, 05:00:48 AM
Me esta pasando lo mismo pero igual hiciste un re quilombo jaja