Social Networking

I am trying to integrate the Facebook in my app so that i can post comment in the wall as well as i can post the photo at the same time.here is what i did but dont know where have i gone wrong as when i tested it it did not go as i wished.can anybody help me out please.

[lua]-- Comment out the next line when through debugging your app.
io.output():setvbuf(‘no’)

local ui = require(“ui”)
local facebook = require(“facebook”)
local json = require(“json”)

display.setStatusBar( display.HiddenStatusBar )

local fbCommand
local LOGOUT = 1
local SHOW_DIALOG = 2
local POST_MSG = 3
local POST_PHOTO = 4
local GET_USER_INFO = 5
local GET_PLATFORM_INFO = 6

local ButtonOrigY = 175
local ButtonYOffset = 45
local StatusMessageY = 420

local background = display.newImage( “facebook_bkg.png”, true )
background.x = display.contentWidth / 2
background.y = display.contentHeight / 2

local function printTable( t, label, level )
if label then print( label ) end
level = level or 1

if t then
for k,v in pairs( t ) do
local prefix = “”
for i=1,level do
prefix = prefix … “\t”
end

print( prefix … “[” … tostring(k) … "] = " … tostring(v) )
if type( v ) == “table” then
print( prefix … “{” )
printTable( v, nil, level + 1 )
print( prefix … “}” )
end
end
end
end

local function createStatusMessage( message, x, y )
local textObject = display.newText( message, 0, 0, native.systemFontBold, 24 )
textObject:setTextColor( 255,255,255 )

local group = display.newGroup()
group.x = x
group.y = y
group:insert( textObject, true )

local r = 10
local roundedRect = display.newRoundedRect( 0, 0, textObject.contentWidth + 2*r, textObject.contentHeight + 2*r, r )
roundedRect:setFillColor( 55, 55, 55, 190 )
group:insert( 1, roundedRect, true )

group.textObject = textObject
return group
end

local statusMessage = createStatusMessage( " Not connected ", 0.5*display.contentWidth, StatusMessageY )

local function listener( event )

print( “Facebook Listener events:” )

local maxStr = 20
local endStr

for k,v in pairs( event ) do
local valueString = tostring(v)
if string.len(valueString) > maxStr then
endStr = " … #" … tostring(string.len(valueString)) … “)”
else
endStr = “)”
end
print( " " … tostring( k ) … “(” … tostring( string.sub(valueString, 1, maxStr ) ) … endStr )
end

print( “event.name”, event.name )
print( “event.type:”, event.type )
print( "isError: " … tostring( event.isError ) )
print( "didComplete: " … tostring( event.didComplete) )

if ( “session” == event.type ) then
statusMessage.textObject.text = event.phase

print( "Session Status: " … event.phase )

if event.phase ~= “login” then
return
end

– The following displays a Facebook dialog box for posting to your Facebook Wall
if fbCommand == SHOW_DIALOG then
facebook.showDialog( {action=“stream.publish”} )

local attachment = {
name = “Developing a Facebook Connect app using the Corona SDK!”,
link = “http://developer.anscamobile.com/forum”,
caption = “Link caption”,
description = “Corona SDK for developing iOS and Android apps with the same code base.”,
picture = “http://developer.anscamobile.com/demo/Corona90x90.png”,
actions = json.encode( { { name = “Learn More”, link = “http://anscamobile.com” } } )
}

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

end

if fbCommand == GET_PLATFORM_INFO then
facebook.request( “platform” )
end

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

if ( not event.isError ) then
response = json.decode( event.response )

else
statusMessage.textObject.text = “Post failed”
printTable( event.response, “Post Failed Response”, 3 )
end

elseif ( “dialog” == event.type ) then
print( “dialog response:”, event.response )
statusMessage.textObject.text = event.response
end
end

local appId = “172031016222278”
local apiKey = “bf4e325418a647cbf7bcf8c9b2bc09b3”

if ( appId ) then

– ************************ Buttons Functions ********************************

local function showDialog_onRelease( event )
– call the login method of the FB session object, passing in a handler
– to be called upon successful login.
fbCommand = SHOW_DIALOG
facebook.login( appId, listener, {“publish_stream”} )
end

local function logOut_onRelease( event )
fbCommand = LOGOUT
facebook.logout()
end
–**********************************************************************************

local fbButton = ui.newButton{
default = “fbButton184.png”,
over = “fbButtonOver184.png”,
onRelease = showDialog_onRelease,
text = " Post in Wall",
x = 160,
y = ButtonOrigY + ButtonYOffset * 2
}

local fbButton = ui.newButton{
default = “fbButton184.png”,
over = “fbButtonOver184.png”,
onRelease = logOut_onRelease,
text = “Logout”,
x = 160,
y = ButtonOrigY + ButtonYOffset * 4
}
end[/lua] [import]uid: 82446 topic_id: 17706 reply_id: 317706[/import]