question about event.type==request, when will it trigger?

Dear all, 

I am trying to create a function for ppl to click a button and then allow them to post a feed (or dialogue? which one is better?) on their wall.

here is my code:


local _W=display.contentWidth

local _H=display.contentHeight

local facebook = require “facebook”

local fb_username = “”  – this should be the name

local fb_gender = “” – him or her

local attachement = {

    name = fb_username…" has a new record!",

    message = fb_username…" has a new record!",

    link = “the link url”,

    caption = “the caption”,

    description = “The record of “…fb_username…” is “…fb_record…”, let’s try to beat “…fb_gender…” now!”,

    picture = “xxx.jpg”,

}

local appId = “1234567890102010” – i know it is app id

local btn = display.newRect(0,0,100,100)

btn:setFillColor(255,255,255)

btn.x,btn.y = _W/2, _H/2

local function facebooklistener(event)

    if(event.type == “session”) then

        if event.phase == “login” then

             facebook.request(“me/feed”,“POST”,attachement)

        end

    elseif(event.type == “request”) then

    end

end

local function facebookfun ()

    facebook.login(appId,facebooklistener,{“publish_actions”})

end

btn:addEventListener(“tap”,facebookfun)


by this, i can successfully post on facebook after login, however, i woundering when will the event.type == “request” ?

I want to change the username and gender to fit the user information…

i know you can do something like:

response = event.response

data = json.decode(response)

fb_username = data.username  – i don’t know if it is right / wrong…

…etc…

in the “request” block, but it seems that the esleif (event.type==“request”) will never call

can anyone help? i will explain more if needed.

You’ll see event.type == “request” in your facebooklistener function when it’s called with the response to your call to facebook.request().  What makes you think that it will never call?

  • Andrew

My Listener:


local function facebooklistener(event)

    if(event.type == “session”) then

        if event.phase == “login” then

            facebook.request(“me”,“GET”)

        end

    elseif(event.type == “request”) then

        native.showAlert(“request”,“request”)

    end

end


but the alert never show up :frowning:

it show up if i put it in “session”

I actually want to change the fb_username to the name of the user, so I want to call a facebook.request(“me”,“GET”) and then get the username of the user and change the fb_username to it. lol not sure how to do that

Wow I don’t know why but I suddenly solved the problem lol

The solutions is like this:

local function facebooklistener(event)

    if(event.type == “session”) then

        if event.phase == “login” then

            facebook.request(“me”)

        end

    elseif(event.type == “request”) then

        userdata = json.decode(event.response)

        fb_username = userdata.name

        if userdata.gender == “male” then

            fb_gender = “him”

        elseif userdata.gender == “female” then

            fb_gender = “her”

        end

        local attachement = {

            name = fb_username…" has a new record in Gloomy Popping!",

            message = fb_username…" has a new record in Gloomy Popping!",

            link = “https://play.google.com/store/apps/details?id=com.DeErStudio.Gloomy_Popping”,

            caption = “https://play.google.com/store/apps/details?id=com.DeErStudio.Gloomy_Popping”,

            description = “The record of “…fb_username…” is “…fb_record…”, let’s try to beat “…fb_gender…” now!”,

            picture = “image url”,

        }

        facebook.request(“me/feed”,“POST”,attachement)

    end

end


Thanks guys!

* and Gloomy Popping is my first game by corona lol pls take a look and give comment :smiley:

You’ll see event.type == “request” in your facebooklistener function when it’s called with the response to your call to facebook.request().  What makes you think that it will never call?

  • Andrew

My Listener:


local function facebooklistener(event)

    if(event.type == “session”) then

        if event.phase == “login” then

            facebook.request(“me”,“GET”)

        end

    elseif(event.type == “request”) then

        native.showAlert(“request”,“request”)

    end

end


but the alert never show up :frowning:

it show up if i put it in “session”

I actually want to change the fb_username to the name of the user, so I want to call a facebook.request(“me”,“GET”) and then get the username of the user and change the fb_username to it. lol not sure how to do that

Wow I don’t know why but I suddenly solved the problem lol

The solutions is like this:

local function facebooklistener(event)

    if(event.type == “session”) then

        if event.phase == “login” then

            facebook.request(“me”)

        end

    elseif(event.type == “request”) then

        userdata = json.decode(event.response)

        fb_username = userdata.name

        if userdata.gender == “male” then

            fb_gender = “him”

        elseif userdata.gender == “female” then

            fb_gender = “her”

        end

        local attachement = {

            name = fb_username…" has a new record in Gloomy Popping!",

            message = fb_username…" has a new record in Gloomy Popping!",

            link = “https://play.google.com/store/apps/details?id=com.DeErStudio.Gloomy_Popping”,

            caption = “https://play.google.com/store/apps/details?id=com.DeErStudio.Gloomy_Popping”,

            description = “The record of “…fb_username…” is “…fb_record…”, let’s try to beat “…fb_gender…” now!”,

            picture = “image url”,

        }

        facebook.request(“me/feed”,“POST”,attachement)

    end

end


Thanks guys!

* and Gloomy Popping is my first game by corona lol pls take a look and give comment :smiley: