Problem With Twitter Plugin

HI Anil,

I was running that main.lua on a Mac yesterday. I pulled out my Windows machine today and I get the same error as you. Likewise, the demo project (which ran fine on a Windows machine a few months ago) is running into weird Runtime errors on the most recent daily build. I’m not sure what’s going on yet, but it’s definitely only on Windows as far as I can tell. If you have time, please try a device build of your app and let me know if things are working there as expected. I’m going to try downloading older Corona builds to pinpoint at which point something changed in the Windows simulator that is causing these errors. We’ll get to the bottom of it eventually - please be patient with me in the meantime.

Thanks,

Jason

Hi Jason,

I have just built the app for my device and unlike the Simulator where I would get a console error but the tweet would go through, on the device the tweet does not go through at all.

Thanks

Well this just gets stranger and stranger. What type of device are you running this on? Can you provide a device error log?

Thanks,

Jason

Jason,

I tested on a Kindle Fire HD7 as that was the device I had to hand but will build it on a HTC and a Samsung phone later today and let you know the results.

Unfortunately, I don’t have Android debugging and the SDK Manager loaded so can’t give you a device error log.

Hi Jason,

Unfortunately I also get the same issue when I try to send a tweet with an image using both the HTC and Samsung phones. Tweets without images get sent fine.

Do you know which version of Corona SDK is best to use - I don’t need to use the latest daily buiild.

Thanks

Anil

Hi Jason,

Have you been able to get to the bottom of this yet?

I have tried rebuilding my app using the recent public build and still am unable to tweet with an image.

In fact, even building the simplest app with just your sample main.lua below does not work either.

local twitter = require("plugin.twitter") twitter.init("XXX", "XXX") -- replace those XXXs with your Twitter app's API key & secret local function tweetCallback( response ) print("TWEET TEXT: " .. response.text) print("TWEET ID: " .. response.id) end twitter.tweet( "A test tweet", "test.png", tweetCallback )

Thanks

Hi Anil,

Sorry. I had some contract work pop up unexpectedly that is taking up my dev time. I’ll do my best to sort things out ASAP. Stay tuned. Might have to be later this week but I’ll get to the bottom of it.

Hi,

Congrats on your new job and love your work on the BeeAmazed app!

Hate to ask but any news on the Twitter bug?

Thanks

@Anil: thanks for checking in. No fix yet, but I’m hoping to spend some time with it tonight. Things have been a bit busy lately, which is a flimsy excuse, I know, but I so appreciate your patience. (And thanks for the kind words about BeeAmazed!)

Stay tuned - I hope to get this thing fixed for you ASAP.

Hi Anil,

Just confirming that I hope to have this worked out this week for sure, and hopefully in the next day or two. Life has been conspiring to keep me away from the Twitter plugin, but I’m pushing back big time this week!

Thanks,

jason

Thanks for the update Jason - you’re a star!!!

@Anil - I’m happy to report that the issue is FIXED and I’ve pushed an updated version of the plugin to Corona’s build servers. It could take an hour or two before the update actually makes its way to you via the Simulator, but it should be all fixed now. Let me know if that’s not the case.

In case you’re interested, the issue was that the JSON string that gets returned by Twitter when you post a tweet was getting corrupted on Windows and Android devices when you included an image. Not sure why it happened, and honestly I implemented a bit of a hacky fix (if valid JSON isn’t returned, I fake an empty lua table in its place). But it stops that Runtime error, and your tweets do get posted. The downside is that it doesn’t pass a valid tweet ID into your listener function, because I have no way of retrieving that from the corrupted JSON string. I’m trying to work with Corona to figure out why Windows and Android don’t get the same valid response as OS X and iOS, but for now it’s better than it was. No Runtime errors or crashes! :slight_smile:

As for why you couldn’t post an image on your Android device, that’s nothing to do with the plugin, but rather it’s a limitation of the access we get to the system.ResourceDirectory on Android - but fear not, I’ve got a fix for you. Will detail that in a second post momentarily…

Okay, so there have been numerous forum posts in the past about getting local HTML files to load in a webview on Android. It’s traditionally been a huge pain because for whatever reason Android wouldn’t read files from the system.ResourceDirectory. I believe that Corona has managed to fix this so that opening local webpages is nice and easy. HOWEVER, when I tried posting a tweet with an image attached on my own Android device, I got an error message saying that it couldn’t find the image I wanted to upload, even though it was sitting right there in my app’s resource directory. This seemed familiar, so I tried using a workaround that I used last year before Corona fixed the whole HTML thing.

The big thing to remember here is that images that are in your system.DocumentsDirectory can be attached to tweets just fine. So if you’re trying to attach an image that you downloaded to system.DocumentsDirectory, or one that you generated within the app via display.capture(), then you shouldn’t have any problems. BUT - if you want to attach an image that resides in your resource directory, you’ve got to copy that file over manually. And to make matters worse, for whatever reason, it doesn’t work with images that have .jpg or .png file extensions. But if you put an image file in your resource directory and change its file extension from .jpg or .png to .txt, then you can copy that file to your documents directory and rename it with the right file extension, and then you can attach it to your tweet! I know it’s a pain, but I tested it using the system below and it worked for me. Here’s how you do it:

First, add a file called copyFile.lua to your project with the following code:

-------------------------------------------------------------------------------- -- CHECK IF A FILE EXISTS -------------------------------------------------------------------------------- local function fileExists(filePath) local exists = false local fileHandle = io.open( filePath, "r" ) if (fileHandle) then -- nil if no file found exists = true io.close(fileHandle) end return(exists) end -------------------------------------------------------------------------------- -- COPY A FILE -------------------------------------------------------------------------------- local function copyFile(source, destination) if not fileExists(source) then return nil end local sourceFile = io.open( source, "r" ) local destinationFile = io.open( destination, "w" ) local fileData = sourceFile:read( "\*a" ) if not fileData then print( "read error!" ) return false else if not destinationFile:write( fileData ) then print( "write error!" ) return false end end sourceFile:close() destinationFile:close() return true end return copyFile

Then require that module into your project like so:

local copyFile = require("copyFile")

Then copy your image file (with the fake “.txt” file extension) to your documents directory like so, giving the copy the right file extension:

copyFile(system.pathForFile("tweetImage.txt", system.ResourceDirectory), system.pathForFile("tweetImage.jpg", system.DocumentsDirectory))

Now that you’ve made copy in your documents directory, which your Android device can see and work with, you can tweet that image out like so:

twitter.tweet("Wow this was a lot of work to tweet this image!", "tweetImage.jpg", callbackListener)

I hope that all makes sense. I know it’s a lot of work, but keep in mind that if you are tweeting images that are already in your system.DocumentsDirectory then none of this stuff needs to happen - you can go ahead and tweet those images easy-peasy. Thanks for your patience, and enjoy! :slight_smile:

Hi @Anil, just confirming that the latest version of the Plugin is live and should automatically download next time you fire up the Simulator. And I just posted an image successfully from the Windows simulator using the actual live plugin, so you should be good to go! Thanks again for your patience.

Thanks for the hard work - we all appreciate it.

Will test it out tomorrow and let you know if all is good.