Creating Facebook app for Android - quesiton

Have a look at the following blog post on how to upload photos to facebook…
http://www.coronalabs.com/blog/2011/12/16/uploading-photos-to-facebook-in-corona/

When calling media.show() to take a picture with the camera, I highly recommend that you set the 3rd argument so that it will save to file. This allows your app to receive a full sized photo from the camera. If you do not set the 3rd argument, then your app will receive a reduced sized photo that will appear on screen. The reason the photo is reduced in size is to fit within the OpenGL rendering system max texture size limit and also due to memory limitations on low-end Android devices. Have a look at the following API documentation for more details…
http://docs.coronalabs.com/api/library/media/show.html

I hope this helps! [import]uid: 32256 topic_id: 32551 reply_id: 130039[/import]

Thanks for this information. It will be very helpful while working on my Facebook app.

Do you know how to save a picture from the camera to sent to my Facebook page? I made a post about this and have not gotten any replies. I even posted I would pay for an answer.

Thanks!
[import]uid: 184193 topic_id: 32551 reply_id: 130024[/import]

@Joshua,
I am using display.save to capture the screen. In the simulator I can look in the corona sandbox and see the saved image, however when I then upload it to share on facebook, the image looked all stretched and skewed in a weird way, have you come across this issue before? [import]uid: 19620 topic_id: 32551 reply_id: 130046[/import]

Well I know how to save a picture from the corona display screen, but not from the phones camera. For this scenario you can use “display.save”. Sorry not sure about using the phones camera [import]uid: 19620 topic_id: 32551 reply_id: 130033[/import]

The following code grabs a picture from the camera and is loaded into the image variable. Do you know how to save the image from here to file?

--   
-- Abstract: Camera sample app  
--   
-- Version: 1.2  
--   
-- Updated: September 21, 2011  
--  
-- Update History:  
-- v1.1 Fixed logic problem where it said "session was cancelled".  
-- v1.2 Added Android support.  
--  
-- Sample code is MIT licensed, see http://www.coronalabs.com/links/code/license  
-- Copyright (C) 2011 Corona Labs Inc. All Rights Reserved.  
---------------------------------------------------------------------------------------  
-- Camera not supported on simulator.   
local isXcodeSimulator = "iPhone Simulator" == system.getInfo("model")  
if (isXcodeSimulator) then  
 local alert = native.showAlert( "Information", "Camera API not available on iOS Simulator.", { "OK"})   
end  
  
--  
local bkgd = display.newRect( 0, 0, display.contentWidth, display.contentHeight )  
bkgd:setFillColor( 128, 0, 0 )  
  
local text = display.newText( "Tap anywhere to launch Camera", 0, 0, nil, 16 )  
text:setTextColor( 255, 255, 255 )  
text.x = 0.5 \* display.contentWidth  
text.y = 0.5 \* display.contentHeight  
  
local sessionComplete = function(event)   
 local image = event.target  
  
 print( "Camera ", ( image and "returned an image" ) or "session was cancelled" )  
 print( "event name: " .. event.name )  
 print( "target: " .. tostring( image ) )  
  
 if image then  
 -- center image on screen  
 image.x = display.contentWidth/2  
 image.y = display.contentHeight/2  
 local w = image.width  
 local h = image.height  
 print( "w,h = ".. w .."," .. h )  
 native.showAlert("Corona", "See image???")  
 end  
end  
  
local listener = function( event )  
 if media.hasSource( media.Camera ) then  
 media.show( media.Camera, sessionComplete )  
 else  
 native.showAlert("Corona", "Camera not found.")  
 end  
 return true  
end  
bkgd:addEventListener( "tap", listener )  

[import]uid: 184193 topic_id: 32551 reply_id: 130038[/import]

I haven’t seen that issue before. Try e-mailing the image file that was created by display.save() to yourself to verify that the file is okay. You can do so via our [lua]native.showPopup()[/lua] API.
http://docs.coronalabs.com/api/library/native/showPopup.html

If the e-mail image file is okay, then we know it’s a facebook issue that we have to work-around. [import]uid: 32256 topic_id: 32551 reply_id: 130051[/import]

Have a look at the following blog post on how to upload photos to facebook…
http://www.coronalabs.com/blog/2011/12/16/uploading-photos-to-facebook-in-corona/

When calling media.show() to take a picture with the camera, I highly recommend that you set the 3rd argument so that it will save to file. This allows your app to receive a full sized photo from the camera. If you do not set the 3rd argument, then your app will receive a reduced sized photo that will appear on screen. The reason the photo is reduced in size is to fit within the OpenGL rendering system max texture size limit and also due to memory limitations on low-end Android devices. Have a look at the following API documentation for more details…
http://docs.coronalabs.com/api/library/media/show.html

I hope this helps! [import]uid: 32256 topic_id: 32551 reply_id: 130039[/import]

Just curious why would you want to save the image displayed on your phone rather than the entire image captured by the camera? Are you still able to save the entire image or just the part that is shown on the phone?
[import]uid: 184193 topic_id: 32551 reply_id: 130052[/import]

@Joshua,
I am using display.save to capture the screen. In the simulator I can look in the corona sandbox and see the saved image, however when I then upload it to share on facebook, the image looked all stretched and skewed in a weird way, have you come across this issue before? [import]uid: 19620 topic_id: 32551 reply_id: 130046[/import]

So if I do the following with the media.show it will save the image to the filename specified?

media.show( media.Camera, onComplete,{ baseDir=system.ResourceDirectory, filename="picture1.jpg", type="image" } )  

Thanks!
[import]uid: 184193 topic_id: 32551 reply_id: 130061[/import]

I haven’t seen that issue before. Try e-mailing the image file that was created by display.save() to yourself to verify that the file is okay. You can do so via our [lua]native.showPopup()[/lua] API.
http://docs.coronalabs.com/api/library/native/showPopup.html

If the e-mail image file is okay, then we know it’s a facebook issue that we have to work-around. [import]uid: 32256 topic_id: 32551 reply_id: 130051[/import]

Here is what I did and it took the picture from the camera but returned back to the main screen to tap to launch the camera. It did not show the Facebook login part. Why?

-----------------------------------------------------------------------------------------  
--  
-- main.lua  
--  
-----------------------------------------------------------------------------------------  
  
-- Your code here  
  
local facebook = require "facebook"  
   
local appId = "12434435235325432543254"  
   
  
local bkgd = display.newRect( 0, 0, display.contentWidth, display.contentHeight )  
bkgd:setFillColor( 128, 0, 0 )  
  
local text = display.newText( "Tap anywhere to launch Camera", 0, 0, nil, 16 )  
text:setTextColor( 255, 255, 255 )  
text.x = 0.5 \* display.contentWidth  
text.y = 0.5 \* display.contentHeight  
local onComplete = function(event)  
 local photo = event.target  
 photo.isVisible = false  
 facebook.login( appId, fbListener, { "publish\_stream" } )  
end  
   
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  
   
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="picture1.jpg", type="image" }  
 }  
  
 facebook.request( "me/photos", "POST", attachment )  
end  
  
local listener = function( event )  
 if media.hasSource( media.Camera ) then  
 media.show( media.Camera, onComplete,{ baseDir=system.ResourceDirectory, filename="picture1.jpg", type="image" } )  
 else  
 native.showAlert("Corona", "Camera not found.")  
 end  
 return true  
end  
  
bkgd:addEventListener( "tap", listener )  

[import]uid: 184193 topic_id: 32551 reply_id: 130062[/import]

Just curious why would you want to save the image displayed on your phone rather than the entire image captured by the camera? Are you still able to save the entire image or just the part that is shown on the phone?
[import]uid: 184193 topic_id: 32551 reply_id: 130052[/import]

So if I do the following with the media.show it will save the image to the filename specified?

media.show( media.Camera, onComplete,{ baseDir=system.ResourceDirectory, filename="picture1.jpg", type="image" } )  

Thanks!
[import]uid: 184193 topic_id: 32551 reply_id: 130061[/import]

Here is what I did and it took the picture from the camera but returned back to the main screen to tap to launch the camera. It did not show the Facebook login part. Why?

-----------------------------------------------------------------------------------------  
--  
-- main.lua  
--  
-----------------------------------------------------------------------------------------  
  
-- Your code here  
  
local facebook = require "facebook"  
   
local appId = "12434435235325432543254"  
   
  
local bkgd = display.newRect( 0, 0, display.contentWidth, display.contentHeight )  
bkgd:setFillColor( 128, 0, 0 )  
  
local text = display.newText( "Tap anywhere to launch Camera", 0, 0, nil, 16 )  
text:setTextColor( 255, 255, 255 )  
text.x = 0.5 \* display.contentWidth  
text.y = 0.5 \* display.contentHeight  
local onComplete = function(event)  
 local photo = event.target  
 photo.isVisible = false  
 facebook.login( appId, fbListener, { "publish\_stream" } )  
end  
   
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  
   
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="picture1.jpg", type="image" }  
 }  
  
 facebook.request( "me/photos", "POST", attachment )  
end  
  
local listener = function( event )  
 if media.hasSource( media.Camera ) then  
 media.show( media.Camera, onComplete,{ baseDir=system.ResourceDirectory, filename="picture1.jpg", type="image" } )  
 else  
 native.showAlert("Corona", "Camera not found.")  
 end  
 return true  
end  
  
bkgd:addEventListener( "tap", listener )  

[import]uid: 184193 topic_id: 32551 reply_id: 130062[/import]

@Joshua,
I took a snapshot with display.save and emailed it to myself and the image is showing the same issue of being VERY distorted… I have a Galaxy SIII but I do have it rooted and running cynogenmod, so I wonder if that could have anything to do with it? For now I will try and have a friend test this as well. [import]uid: 19620 topic_id: 32551 reply_id: 130102[/import]

@joshua,
just tested it on a stock unrooted phone and am seeing the same problem, I can send you images of what it looks like if it would be helpful…

Also display.captureScreen seems to work fine except that using that API call only allows you to save the screen capture to the users photo album right? No way to just email it or paste it to facebook from the corona apps temp/documents? [import]uid: 19620 topic_id: 32551 reply_id: 130103[/import]

rxmarccall,

Sounds like you’ve found a bug with display.save(). It may be device specific or its the pixel size of the image that you are capturing (ie: a stride issue), because this issue does not happen on my Galaxy Nexus. Probably some edge case that we didn’t think of.

Would you mind sending us a small sample project that reproduces this display.save() issue please? You can do so by clicking the “Report a Bug” link at the top of this web page. [import]uid: 32256 topic_id: 32551 reply_id: 130108[/import]

@Joshua,
I took a snapshot with display.save and emailed it to myself and the image is showing the same issue of being VERY distorted… I have a Galaxy SIII but I do have it rooted and running cynogenmod, so I wonder if that could have anything to do with it? For now I will try and have a friend test this as well. [import]uid: 19620 topic_id: 32551 reply_id: 130102[/import]

@joshua,
just tested it on a stock unrooted phone and am seeing the same problem, I can send you images of what it looks like if it would be helpful…

Also display.captureScreen seems to work fine except that using that API call only allows you to save the screen capture to the users photo album right? No way to just email it or paste it to facebook from the corona apps temp/documents? [import]uid: 19620 topic_id: 32551 reply_id: 130103[/import]