So I’ve been messing with corona for a few months now jumping from idea to idea only to put it off for when I am more experienced with corona. Well now i have this app I’ve been working on and have this last feature left and cannot find anything on it. I want to send a Facebook friend request from my app. Is that possible? my idea is, there would be 2 phones running this app and they each push a friend request to the other phone. I don’t think it’s in the Facebook API but I was thinking it could push a URL with the user’s Facebook ID to the other phone. How would I go about this? [import]uid: 146992 topic_id: 29170 reply_id: 329170[/import]
I also have the one time facebook sign in setup on my app so I would like the user to never have to sign in again. [import]uid: 146992 topic_id: 29170 reply_id: 117329[/import]
@d2391, maybe the following will help get you started:
http://www.coronalabs.com/blog/2011/12/16/uploading-photos-to-facebook-in-corona/
http://www.coronalabs.com/blog/2012/01/04/implementing-facebook-single-sign-on/
Good luck.
Naomi [import]uid: 67217 topic_id: 29170 reply_id: 117355[/import]
Yeah I’ve already read those. What I’m looking for is to send friend requests between 2 phone [import]uid: 146992 topic_id: 29170 reply_id: 117356[/import]
Are you trying to have two people who are not FB friends to become friends by having them exchange friend requests? I wonder if you can even do something like that on the web, i.e., A signs in to FB, and somehow send FB friend request to B (and I have no idea how A knows B), and at the same time, you want B to send friend request to A. So, essentially, you want two people who are not FB friends to become friends using their phone.
I suppose, if you can do this on the web using browser, you might be able to find the way to do so on the phone too. I’m interested in finding out how you might achieve this. I wonder if someone has already done this using Corona.
Naomi [import]uid: 67217 topic_id: 29170 reply_id: 117357[/import]
Sorry, I should have been more clear, the 2 phones would be close so i could use something like say… bluetooth to connect the phones. You can use this url http://www.facebook.com/addfriend.php?id=[facebook ID] to send friend requests. Each profile has a Facebook ID, so if A and B both logged in to Facebook on the app, the app somehow got each of their Facebook ID’s, put the ID’s into that URL above and the A’s phone sent that URL to B and B sent to A
How would I get the app to grab the user’s Facebook ID? is there any way to do it without a safari window? is there a better way to do what I am trying to accomplish? [import]uid: 146992 topic_id: 29170 reply_id: 117359[/import]
Out of curiosity, I googled a bit, and it sounds like you’d need access token of the user to get his/her userID:
https://developers.facebook.com/tools/explorer?method=GET&path=me
Edit: It looks like you can fetch the access token:
http://developer.coronalabs.com/reference/index/facebooklogin
If you are able to solve this, I’d be so interested in seeing some code snippets that shows how you put them together to enable this.
Naomi [import]uid: 67217 topic_id: 29170 reply_id: 117436[/import]
ok so I’ve made some progress by using code from http://developer.anscamobile.com/sample-code/networking but my problem is that I have upgraded to Mountain Lion and when I try to build for iOS it displays this error… The iOS SDK could not be found. Please install the iOS SDK.
I’ve uninstalled and reinstalled Xcode and still nothing and since the corona sim doesn’t support fbconnect, I cannot test the code.
The last thing I need to do is take the ID that I get and insert it into the URL. Anyone have an idea on how to do that?
anyways, here’s the code
[lua]-- Comment out the next line when through debugging your app.
io.output():setvbuf(‘no’) – **debug: disable output buffering for Xcode Console **tjn
– Load external library (should be in the same folder as main.lua)
local ui = require(“ui”)
local facebook = require(“facebook”)
local json = require(“json”)
– Facebook Commands
local fbCommand – forward reference
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
– Layout Locations
local StatusMessageY = 420 – position of status message
– This function is useful for debugging problems with using FB Connect’s web api,
– e.g. you passed bad parameters to the web api and get a response table back
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 )
– Show text, using default bold font of device (Helvetica on iPhone)
–local textObject = display.newText( message, 0, 0, native.systemFontBold, 24 )
–textObject:setTextColor( 255,255,255 )
– A trick to get text to be centered
–local group = display.newGroup()
–group.x = x
–group.y = y
–group:insert( textObject, true )
– Insert rounded rect behind textObject
–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 )
– New Facebook Connection listener
local function listener( event )
— Debug Event parameters printout --------------------------------------------------
— Prints Events received up to 20 characters. Prints “…” and total count if longer
print( “Facebook Listener events:” )
local maxStr = 20 – set maximum string length
local endStr
for k,v in pairs( event ) do
if string.len(v) > maxStr then
endStr = " … #" … tostring(string.len(v)) … “)”
else
endStr = “)”
end
print( " " … tostring( k ) … “(” … tostring( string.sub(v, 1, maxStr ) ) … endStr )
end
— End of debug Event routine -------------------------------------------------------
print( “event.name”, event.name ) – “fbconnect”
print( “event.type:”, event.type ) – type is either “session” or “request” or “dialog”
print( "isError: " … tostring( event.isError ) )
print( "didComplete: " … tostring( event.didComplete) )
– After a successful login event, send the FB command
– Note: If the app is already logged in, we will still get a “login” phase
if ( “session” == event.type ) then
– event.phase is one of: “login”, “loginFailed”, “loginCancelled”, “logout”
statusMessage.textObject.text = event.phase – tjn Added
print( "Session Status: " … event.phase )
if event.phase ~= “login” then
– Exit if login error
return
end
– Request the current logged in user’s info
if fbCommand == GET_USER_INFO then
facebook.request( “me”, id)
– facebook.request( “me/friends” ) – Alternate request
end
elseif ( “request” == event.type ) then
– event.response is a JSON object from the FB server
local response = event.response
if ( not event.isError ) then
response = json.decode( event.response )
if fbCommand == GET_USER_INFO then
statusMessage.textObject.text = response.name
printTable( response, “User Info”, 3 )
print( “id”, response.name )
else
– Unknown command response
print( “Unknown command response” )
statusMessage.textObject.text = “Unknown ?”
end
else
– Post Failed
statusMessage.textObject.text = “Post failed”
printTable( event.response, “Post Failed Response”, 3 )
end
elseif ( “dialog” == event.type ) then
– showDialog response
print( “dialog response:”, event.response )
statusMessage.textObject.text = event.response
end
end
– NOTE: To create a mobile app that interacts with Facebook Connect, first log into Facebook
– and create a new Facebook application. That will give you the “API key” and “application secret”
– that should be used in the following lines:
local appId = – Add your App ID here
local apiKey = nil – Not needed at this time
– NOTE: You must provide a valid application id provided from Facebook
if ( appId ) then
– ***
– ************************ Buttons Functions ********************************
– ***
local function getInfo_onRelease( event )
– call the login method of the FB session object, passing in a handler
– to be called upon successful login.
fbCommand = GET_USER_INFO
facebook.login( app id, listener, {“publish_stream”} )
end
– ***
– ************************ Create Buttons ********************************
– ***
– “Get User Info with Facebook” button
local fbButton = ui.newButton{
default = “fb.png”,
onRelease = getInfo_onRelease,
x = 160,
y = 430,
}
else
– Handle the response from showAlert dialog boxbox
local function onComplete( event )
if event.index == 1 then
system.openURL( “http://developers.facebook.com/get_started.php” )
end
end
native.showAlert( “Error”, “To develop for Facebook Connect, you need to get an API key and application secret. This is available from Facebook’s website.”,
{ “Learn More”, “Cancel” }, onComplete )
end
[import]uid: 146992 topic_id: 29170 reply_id: 118327[/import]