I want to connect to facebook and retrieve my friends name and last name.
The code I used is the following.
local function listener()
print("enter Event listener")
if("session" == event.type) then -- getting the session from facebook
print("sesion")
if("login" == event.phase) then
facebook.request("me/friends")
end
elseif("request"==event.type) then
local response=event.response
if (not event.isError) then
response = json.decode( event.response )
data = response.data
local function showImage( event )
print("Writing to a file")
end
-- Getting the data from the local data and storing it in the file
for i=1,#data do
local id = data[i].id
network.download("https://graphs.facebook.com/"..id,"GET",showImage,id..".txt",system.DocumentsDirectory)
end
end
end
end
-- getting the response in json format and decoding it
local appId="255979881130641"
if(appId) then
local function onClick(event)
if event.phase == "ended" then
print("enter on click function")
facebook.login(appId,listener,{"publish\_stream"})
end
end
local myButton=display.newImage("images/fb.png")
myButton.x=display.contentWidth/2
myButton.y=display.contentHeight/2
myButton:addEventListener("touch",onClick)
else
local function onComplete( event )
system.openURL( "http://developers.facebook.com/setup" )
end
native.showAlert( "Error", "To develop for Facebook Connect, you need to get an application id from Facebook's website.", { "Learn More" }, onComplete )
end
How ever I am not able to access the data. Whether the above code is correct or wrong! I am not able to verify. I would be grateful, if anyone explained to me the proper steps?
[import]uid: 94953 topic_id: 19054 reply_id: 319054[/import]