Serious bugs in facebook.request() and network.upload()

Hello!

For our app, we need to post screenshots to Facebook albums.

There are several problems with this:

  1. facebook.request(“me/photos”) gives “facebook sdk error 5”. This seems to have broken for a year, despite hefty forum discussions earlier this year.
  2. So I decided to upload the photo to my own server and post to Facebook from there. But then the built-in Corona function network.upload() just doesn’t work either. Seems to have been broken for several years.
  3. So I used an upload workaround the user “bpappin” posted in 2011. So now I am able to upload photos.

However, there are two issues:

  1. The JPEG screenshot generated by display.save() is over 200K, which takes over 10 seconds to upload on a mediocre 3G connection.
  2. Moreover, bpappin’s workaround encodes the image as base64, adding an extra 25% to the file size and upload time.

My questions to Corona:

  1. Can you repair facebook.request(“me/photos”)?
  2. Can you repair network.upload()?

Thank you for your attention and hope this will be seriously addressed soon.

Do you have some sample code of the “me/photos” issue?

It takes a while to put together a stand-alone sample code, so before I do this, I’d like to know your perception of the situation. Please indicate which of the following statements (a, b, c) are true:

  • a. facebook.request(“me/photos”) and network.upload() are working perfectly when testing them at the Corona offices, so we suspect you (the Developer) may be doing something wrong.
  • b. We know that these functions are broken, we’d just appreciate some sample code to speed up the bug fixing process for the Corona staff.
  • c. We don’t actually know whether these functions work or not, so we need the sample code to investigate the matter.

As far as your #2 point above, network.upload doesn’t work with any random webserver - the server must be configured properly / compatibly. What that server configuration is, however, doesn’t seem to be documented.

The network upload page reads:

“Note: This example demonstrates one possible way to upload a file. Different web servers and applications support different methods of file upload. For example, some REST services support upload of a binary file in the body of a PUT request. Many web servers only allow file uploads using multipart/form-encoded (text) request bodies in a POST request. If you are going to attempt file upload, you must first understand the specific mechanism supported by the specific web server or application
that you will be working with, and then you must form your request data and choose your request method appropriately.”

I’m using a plain vanilla LAMP server, and I also have to base64 encode my data to get the transfer to complete. What would be helpful (to us web-challenged programmers) is some corona documentation on the specific requirements network.upload needs to transfer to a server. Maybe a couple examples that set it up for a straight binary transfer with the most common server setups, and maybe a little php or other server code snippets that are needed in certain setups.

But I’m guessing coronaLabs has bigger fish to fry (more people requesting other things), and that since the upload issues are solvable at the app end (by programmers figuring out how their server is configured on their own and then adjusting their calls(), without coronaLabs writing sample docs for different server setups).

The following Corona blog article provides an example on how to upload a local image file to facebook via a facebook.request() function call.  It uses a “me/photos” request and a file table as a parameter.  It works on both iOS and Android.  Have a look at the instructions here…

   http://www.coronalabs.com/blog/2011/12/16/uploading-photos-to-facebook-in-corona/

I also tested uploading a local PNG file that was 396 kb via a facebook.request() as instructed by the above blog post link with the newest daily build and on an Android device.  It worked.

Here are results from testing album posting with the example code from the blog post.

iPhone build 1153:

Dialog: “The operation couldn’t be completed. (com.facebook.sdk error 5.)”

Xcode Console: “HTTP error 400”.

Result: Failure! No photo in album

iPhone build 1161:

Result: Success! The photo appears in the album.

You must have fixed something in the latest builds, because for the first time ever it is working. I think some people are going to cry from happiness now.

However, Android (build 1161) has a different problem:

  1. A dialog titled “Facebook” asks “<App Name> would like to access your photos and post to your friends on your behalf.” [Cancel] [OK]
  2. I click [OK], and immediately after, the dialog shows a very wide [cancel] button, and some loading happens.
  3. Then ADB console says: event.phase = “loginCancelled”, and no photo appears in the album.

Is this because the large [cancel] button erroneously captures my touch on the [OK], or is there a different cause? At any rate, it does not work. I have the Facebook app installed on Android, and I am logged in.

PS! Let me know if I should file a bug report.

PPS! I was also able to make network.upload() work with a PHP server. $_FILES will be empty, but php://input contains the binary file. You may want to add this to the official documentation.

I know we’ve supported uploading a local image to facebook for over a year.  It worked in the last release version.  That said, since daily build #1141, we’ve updated Corona to use the newest Facebook SDK and have had to fix some minor issues since then.  You might of just ran into an issue with those daily builds.  Just a forewarning, our daily builds are beta versions and do not typically go though full formal testing until near the end of the release.  I recommend that you use the last release version instead.

Regarding posting to your friends, are you sure you’re not missing a facebook permission?  Such as “publish_actions”?  I’m not the facebook expert here, so I don’t know the answer.  Facebook has some permissions documented here…

   http://developers.facebook.com/docs/reference/login/extended-permissions/

@Joshua: Thanks for your your warning about daily builds, though I’ve never experienced particular problems with them.

Anyway, I tried 1137 now (the latest official release).

To be sure, I asked for all thinkable permissions: {“publish_stream”, “publish_actions”, “user_photos”}.

Android:

  • The previous “…post to your friends on your behalf…” dialog was replaced with a beautiful page asking for permission to post in my album.
  • Opon my approval, a dialog said “The photo has been uploaded”, but the Android log says: “{“error”:{“message”:”(#324) Requires upload file",“type”:“OAuthException”,“code”:324}}", even though I specified a file, and the file is in the asset folder.
  • There was no photo posted in my Facebook album.

iPhone:

  • response = “The operation couldn’t be completed. (com.facebook.sdk error 5.)”. We’re there again.
  • There was no photo posted in my Facebook album.

So I am worse off with 1137 than the latest beta build.

If it’s so difficult to get the Facebook SDK right, maybe you should give up on it and spend your energy on other needing parts of the software. Just provide the access token and recommend developers to use their game server to access Facebook instead.

In Norway we have a saying about trekking: “It’s not a shame to turn around”. This may very well be true for software development as well.

I’ve just tested posting a local image file to facebook via release build #1137 and it worked.
I’m using the “publish_stream” permission when doing a facebook.login().
 
What I did was modify our existing “Networking/Facebook” sample app to post the image.  I replaced the “Show Dialog” code to do the following facebook request…

local attachment = { message = "Description of the photo.", source = { baseDir=system.ResourceDirectory, filename="facebook\_bkg.png", type="image" } } facebook.request("me/photos", "POST", attachment)

If it still doesn’t work for you, then perhaps it is an with your developer options on facebook’s website.  I recommend that you view the following facebook guide to see if you have any missing settings on your developer page.

   http://docs.coronalabs.com/daily/guide/social/setupFacebook/index.html

Other than that, I’m not sure what else I can do to help.  I know other Corona developers can post local image files just fine too.  So, what you are running into is not a Corona bug.  Most likely a permission or set up issue.
 

Do you have some sample code of the “me/photos” issue?

It takes a while to put together a stand-alone sample code, so before I do this, I’d like to know your perception of the situation. Please indicate which of the following statements (a, b, c) are true:

  • a. facebook.request(“me/photos”) and network.upload() are working perfectly when testing them at the Corona offices, so we suspect you (the Developer) may be doing something wrong.
  • b. We know that these functions are broken, we’d just appreciate some sample code to speed up the bug fixing process for the Corona staff.
  • c. We don’t actually know whether these functions work or not, so we need the sample code to investigate the matter.

As far as your #2 point above, network.upload doesn’t work with any random webserver - the server must be configured properly / compatibly. What that server configuration is, however, doesn’t seem to be documented.

The network upload page reads:

“Note: This example demonstrates one possible way to upload a file. Different web servers and applications support different methods of file upload. For example, some REST services support upload of a binary file in the body of a PUT request. Many web servers only allow file uploads using multipart/form-encoded (text) request bodies in a POST request. If you are going to attempt file upload, you must first understand the specific mechanism supported by the specific web server or application
that you will be working with, and then you must form your request data and choose your request method appropriately.”

I’m using a plain vanilla LAMP server, and I also have to base64 encode my data to get the transfer to complete. What would be helpful (to us web-challenged programmers) is some corona documentation on the specific requirements network.upload needs to transfer to a server. Maybe a couple examples that set it up for a straight binary transfer with the most common server setups, and maybe a little php or other server code snippets that are needed in certain setups.

But I’m guessing coronaLabs has bigger fish to fry (more people requesting other things), and that since the upload issues are solvable at the app end (by programmers figuring out how their server is configured on their own and then adjusting their calls(), without coronaLabs writing sample docs for different server setups).

The following Corona blog article provides an example on how to upload a local image file to facebook via a facebook.request() function call.  It uses a “me/photos” request and a file table as a parameter.  It works on both iOS and Android.  Have a look at the instructions here…

   http://www.coronalabs.com/blog/2011/12/16/uploading-photos-to-facebook-in-corona/

I also tested uploading a local PNG file that was 396 kb via a facebook.request() as instructed by the above blog post link with the newest daily build and on an Android device.  It worked.

Here are results from testing album posting with the example code from the blog post.

iPhone build 1153:

Dialog: “The operation couldn’t be completed. (com.facebook.sdk error 5.)”

Xcode Console: “HTTP error 400”.

Result: Failure! No photo in album

iPhone build 1161:

Result: Success! The photo appears in the album.

You must have fixed something in the latest builds, because for the first time ever it is working. I think some people are going to cry from happiness now.

However, Android (build 1161) has a different problem:

  1. A dialog titled “Facebook” asks “<App Name> would like to access your photos and post to your friends on your behalf.” [Cancel] [OK]
  2. I click [OK], and immediately after, the dialog shows a very wide [cancel] button, and some loading happens.
  3. Then ADB console says: event.phase = “loginCancelled”, and no photo appears in the album.

Is this because the large [cancel] button erroneously captures my touch on the [OK], or is there a different cause? At any rate, it does not work. I have the Facebook app installed on Android, and I am logged in.

PS! Let me know if I should file a bug report.

PPS! I was also able to make network.upload() work with a PHP server. $_FILES will be empty, but php://input contains the binary file. You may want to add this to the official documentation.

I know we’ve supported uploading a local image to facebook for over a year.  It worked in the last release version.  That said, since daily build #1141, we’ve updated Corona to use the newest Facebook SDK and have had to fix some minor issues since then.  You might of just ran into an issue with those daily builds.  Just a forewarning, our daily builds are beta versions and do not typically go though full formal testing until near the end of the release.  I recommend that you use the last release version instead.

Regarding posting to your friends, are you sure you’re not missing a facebook permission?  Such as “publish_actions”?  I’m not the facebook expert here, so I don’t know the answer.  Facebook has some permissions documented here…

   http://developers.facebook.com/docs/reference/login/extended-permissions/

@Joshua: Thanks for your your warning about daily builds, though I’ve never experienced particular problems with them.

Anyway, I tried 1137 now (the latest official release).

To be sure, I asked for all thinkable permissions: {“publish_stream”, “publish_actions”, “user_photos”}.

Android:

  • The previous “…post to your friends on your behalf…” dialog was replaced with a beautiful page asking for permission to post in my album.
  • Opon my approval, a dialog said “The photo has been uploaded”, but the Android log says: “{“error”:{“message”:”(#324) Requires upload file",“type”:“OAuthException”,“code”:324}}", even though I specified a file, and the file is in the asset folder.
  • There was no photo posted in my Facebook album.

iPhone:

  • response = “The operation couldn’t be completed. (com.facebook.sdk error 5.)”. We’re there again.
  • There was no photo posted in my Facebook album.

So I am worse off with 1137 than the latest beta build.

If it’s so difficult to get the Facebook SDK right, maybe you should give up on it and spend your energy on other needing parts of the software. Just provide the access token and recommend developers to use their game server to access Facebook instead.

In Norway we have a saying about trekking: “It’s not a shame to turn around”. This may very well be true for software development as well.

I’ve just tested posting a local image file to facebook via release build #1137 and it worked.
I’m using the “publish_stream” permission when doing a facebook.login().
 
What I did was modify our existing “Networking/Facebook” sample app to post the image.  I replaced the “Show Dialog” code to do the following facebook request…

local attachment = { message = "Description of the photo.", source = { baseDir=system.ResourceDirectory, filename="facebook\_bkg.png", type="image" } } facebook.request("me/photos", "POST", attachment)

If it still doesn’t work for you, then perhaps it is an with your developer options on facebook’s website.  I recommend that you view the following facebook guide to see if you have any missing settings on your developer page.

   http://docs.coronalabs.com/daily/guide/social/setupFacebook/index.html

Other than that, I’m not sure what else I can do to help.  I know other Corona developers can post local image files just fine too.  So, what you are running into is not a Corona bug.  Most likely a permission or set up issue.