Created
December 19, 2011 04:51
-
-
Save nazt/1495441 to your computer and use it in GitHub Desktop.
Facebook Photo Uploading with Corona SDK
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local facebook = require "facebook" | |
| -- You must use your own app id for this sample to work | |
| local fbAppID = "123456789abcdefghi" --fake | |
| local function onLoginSuccess() | |
| -- Upload 'iheartcorona.jpg' to current user's account | |
| local attachment = { | |
| message = "Just a description of the photo.", | |
| source = { baseDir=system.ResourceDirectory, filename="iheartcorona.jpg", type="image" } | |
| } | |
| facebook.request( "me/photos", "POST", attachment ) | |
| end | |
| -- facebook listener | |
| local function fbListener( event ) | |
| if event.isError then | |
| native.showAlert( "ERROR", event.response, { "OK" } ) | |
| else | |
| if event.type == "session" and event.phase == "login" then | |
| -- login was a success; call function | |
| onLoginSuccess() | |
| elseif event.type == "request" then | |
| -- this block is executed upon successful facebook.request() call | |
| native.showAlert( "Success", "The photo has been uploaded.", { "OK" } ) | |
| end | |
| end | |
| end | |
| -- photo uploading requires the "publish_stream" permission | |
| facebook.login( fbAppID, fbListener, { "publish_stream" } ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment