post screenshot to facebook

im trying to post a screenshot to facebook using this code : 

baseDir = system.DocumentsDirectory display.save( group, "bScore.png", baseDir ) -- display.save( group, "bScore.png", system.ResourceDirectory ) --tried no change! local facebook = require "facebook" local fbAppID = "\*\*\*\*"      function onLoginSuccess()      attachment = {        message = "I have achieved ".. allScore\_txt .. " points playing",         source = { baseDir=system.ResourceDirectory, filename="bScore.png", type="image" }     }  ................

but when its upload it is not finding the file how can i save the screenshot in the “system.ResourceDirectory”

the error is “(#324) Requires upload file”

You cannot write files to system.ResourceDirectory.  If you save it to system.DocumentsDirectory, you then have to load it from system.DocumentsDirectory.

Rob

that works :D 

You cannot write files to system.ResourceDirectory.  If you save it to system.DocumentsDirectory, you then have to load it from system.DocumentsDirectory.

Rob

that works :D 

Hi,

any solution to this issue? I still get an error #324 if I attempt to upload a picture (jpg) from system.DocumentsDirectory

What’s wrong?

Thanks

g

Can you post some code?

Thanks

Rob

Hi Rob,

here my code

local facebook = require( "facebook" ) local fbAppID = "1234567890" -- this is a fake AppID local function onLoginSuccess() local attachment = { message = "Test Message", source = { baseDir=system.DocumentsDirectory, filename="testPicture.jpg", type="image" } } facebook.request( "me/photos", "POST", attachment ) end local json = require( "json" ) 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 facebook.login( fbAppID, fbListener, { "publish\_stream" } )

AppID in the code is not the real one. This code produces a #324 error whereas if I use baseDir=system.ResourceDirectory instead of baseDir=system.DocumentsDirectory everything works fine. Obviously, the picture is inside both directories (in the Build one for ResourceDirectory case and in Sandbox/Documents for DocumentsDirectory.

I also attempted to change picture (different sizes but always JPG).

What’s wrong in my code?

Thanks for your support,

g

When I tried this, if I used system.ResourceDirectory, I got the error.  However if I used system.DocumentsDirectory it worked as it should.  How are you getting the image into your Sandbox Documents?  If you are doing it through the Simulator, that’s only putting it in sandbox for the simulator.  I had to write a little code to download an image to put in my system.DocumentsDirectory.  I guess I could have written a function that would have copied the image from system.ResourcesDirectory to system.DocumentsDirectory.

Also, technically speaking the type should be “image/jpeg” or “image/png” depending on the file type needed, though Facebook didn’t seem to care.

Because on Android, the system.ResourcesDirectory technically doesn’t exist, you may have trouble accessing files in it.  You need to do a system.pathForFile() to cause us to extract it from the zip file.  We do this automatically for images that are accessed via display.* functions. 

Rob

Hey Rob,

I appear to be having a similar issue to the above, rather then opening another Thread I thought I would add to this one for collaboration. 

I have done what you said above with the code below and can see the image is saving successfully to my ResourcesDirectory folder along side my settings but when I access Facebook I get

ERROR

The operation couldn’t be completed (com.facebook error 123.)

2014-06-01%2014.05.18.png

CODE:

[lua]

local function onFaceBookShareRelease( … )

–Read the exiciting FaceBookIcon from the resource directory (image is in same drector as my main.lua and other files)
–Read image and convert image to a binary form
local pathRead = system.pathForFile( “FaceBookIcon.jpg”,system.ResourceDirectory )
local file = io.open( pathRead, “rb” )
local imageData = file:read( “*a” )
io.close( file )

–Setup write directory to my documesnts directoy that my settings have been saved to
–Write the binary file and close and set FileStream back to nil
local pathWrite = system.pathForFile( “FaceBookIcon.jpg”, system.DocumentsDirectory )
local file = io.open( pathWrite, “wb” )
file:write( imageData )
io.close( file )
file = nil

–Setup my Facebook ID
local fbAppID = “1405306663086221” --fake

–iF login = success then create the attachment and send it to facebook
local function onLoginSuccess()
– Upload ‘FaceBookIcon.jpg’ to current user’s account
local attachment = {
message = "I just started playing Beetle Juice, come join me in squashing some bugs! ",
source = { baseDir=system.DocumentsDirectory, filename=“FaceBookIcon.jpg”, type=“image” },
link = “http:roedangames.net”
}

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” } )

end[/lua] 

Hi Salvador, I got this to work I’m my games will post some more information/code tomorrow, I the mean time you need to check the keyhash your using if it’s on a Android

Ps I didn’t realise you can use the link asset… Try it without the link (or add a correct url) see if it works

–link = "http://roedangames.net"

Hi Salvador, here is my code:

local facebook = require "facebook"local fbAppID = "\*\*\*\*\*\*\*\*\*\*\*\*\*"  function onLoginSuccess()       attachment = {         message = "I have achieved ".. score .. " text......",         source = { baseDir=system.DocumentsDirectory, filename="myfile.png", type="image" }     }     facebook.request( "me/photos", "POST", attachment ) end function fbListener( event )     if event.isError then         native.showAlert( "ERROR", event.response, { "OK" } )     else         if event.type == "session" and event.phase == "login" then         onLoginSuccess()         elseif event.type == "request" then local function onComplete( event )     if "clicked" == event.action then         local i = event.index closeloading()         if 1 == i then         end     end end native.showAlert( "Success", "Your Score has been uploaded.", { "OK" }, onComplete )         end     end end facebook.login( fbAppID, fbListener, { "publish\_stream" } )

ps make sure you have thins in you build.settings :

android ={ usesPermissions = {          "android.permission.INTERNET",          "android.permission.ACCESS\_NETWORK\_STATE",          "android.permission.READ\_PHONE\_STATE", }, }, iphone = { plist = { CFBundleVersion = "\*\*\*\*\*",         CFBundleShortVersionString = "\*\*\*\*\*",         CFBundleDisplayName = "\*\*\*\*\*",         CFBundleIdentifier = "\*\*\*\*\*",         UIStatusBarHidden = true,         UIPrerenderedIcon = false, -- set to false for "shine" overlay         UIApplicationExitsOnSuspend = true, -- uncomment to quit app on suspend          CFBundleIconFile = "Icon.png", CFBundleIconFiles = { "Icon@2x.png",  "Icon.png",  "Icon-xhdpi.png",  "Icon-mdpi.png",  "Icon-ldpi.png",  "Icon-hdpi.png",  "Icon-120.png",  "Icon-76@2x.png",  "Icon-76.png",  "Icon-72@2x.png",  "Icon-72.png",  "Icon-60@2x.png",  }, UIApplicationExitsOnSuspend = false, -- must be false for single sign-on to work FacebookAppID = "\*\*\*\*\*", CFBundleURLTypes = { { CFBundleURLSchemes = { "fbXXXXXXXXX", -- replace XXXXXXXXX with your facebook appId \*\*LEAVE THE 'fb' AT THE START\*\* } } } } }

Hi,

I attempted to implement your code but I receive same error as before.

Did you implement it on iOS or Android? It seems to work properly on iOS but not on Android.

I also noticed that if  you use social plugin for Twitter on Android, the photo posting via system.DocumentsDirectory, it didn’t work (the post doesn’t contain any image).

Thanks,

g

Hi I don’t know about the social plugin as I’m not using it, my code work fine on ios and Android, as it’s not working on your Android I suggest you have a look at your key hash you use in your Facebook app setting this is probably the reason for it not working. What key chain are you using to compile the Android application?

It’s not my case - I am able to implement showDialog or other Facebook stuff, except photo uploading.

Can you try to upload just a message without the photo?

Are there other messages in the device’s console log?  If you need help learning to read the console log, read this:

http://coronalabs.com/blog/2013/07/09/tutorial-basic-debugging/

It’s hard to speculate on what the issue is. 

Hi Rob,

unfortunately no warnings or whatever are displayed by log. 

If useful, I can share a video in order to show what happens.

Thanks,

g

Can you still try to just post a status update without the image also can you attach the logcat to your reply

Hi,

attempted to do that, but if I use “me/photos” fb request, the code still gives an error because it expects the parameter “filename” which is missing.

In the end, I am going to put all the image to upload into ResourceDirectory which works. I really don’t understand why DocumentsDirectory is not reachable by Android devices (at least in this case).

Alsto attempted with CacheDirectory and TemporaryDirectory (obviously, I first copied the image via code into those folders) and I still receive the #324 error.

I tested the code on a Kindle Fire and on a Samsung S2.

Logs NEVER gave feedback about that.

I also discovered a very interesting behavior.

If I implement the following code taken from Corona ResourceDirectoy tutorial, none image is shown on the screen (and no uploaded as happened before) (for the reference code, see also http://docs.coronalabs.com/guide/data/readWriteFiles/index.html.

copyFile( "myfile.png", nil, "myfile1.png", system.DocumentsDirectory, true ) local catImage = display.newImage( "myfile.png", system.DocumentsDirectory, 100, 100 ) 

Thanks