Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding image posting functionality

  • Loading branch information...
commit 8c10633557c614f0739bacd462037f9ae2d57610 1 parent d25984f
@GrahamRanson GrahamRanson authored
Showing with 17 additions and 4 deletions.
  1. +10 −3 GGTwitter.lua
  2. +7 −1 README.md
View
13 GGTwitter.lua
@@ -19,7 +19,8 @@
--
-- Requirements:
--
--- oAuth.lua from the Twitter sample included with Corona.
+-- oAuth.lua from here - https://github.com/breinhart/Corona-SDK-Tweet-Media/blob/master/utils/oAuth.lua
+-- multipartForm.lua from here - https://github.com/breinhart/Corona-SDK-Tweet-Media/blob/master/utils/multipartForm.lua
--
-- Copyright (C) 2012 Graham Ranson, Glitch Games Ltd.
--
@@ -267,7 +268,8 @@ end
--- Post a message to the users Twitter feed.
-- @param message The message to post.
-function GGTwitter:post( message )
+-- @param image The filename of an image in system.DocumentsDirectory to post. Optional.
+function GGTwitter:post( message, image )
local params = {}
params[ 1 ] =
@@ -276,7 +278,12 @@ function GGTwitter:post( message )
value = message
}
- oAuth.makeRequest( "http://api.twitter.com/1/statuses/update.json", params, self.consumerKey, self.accessToken, self.consumerSecret, self.accessTokenSecret, "POST" )
+ if image then
+ oAuth.makeRequestWithMedia( "http://upload.twitter.com/1/statuses/update_with_media.json", params, image, self.consumerKey, self.accessToken, self.consumerSecret, self.accessTokenSecret, "POST" )
+ print("A")
+ else
+ oAuth.makeRequest( "http://api.twitter.com/1/statuses/update.json", params, self.consumerKey, self.accessToken, self.consumerSecret, self.accessTokenSecret, "POST" )
+ end
if self.listener then
self.listener{ phase = "posted" }
View
8 README.md
@@ -4,7 +4,8 @@ GGTwitter
GGTwitter makes it very easy to authorise your player with Twitter and post messages.
Authorisation data is stored so that the user only has to login the first time.
-oAuth.lua from the Twitter sample included with Corona is required.
+oAuth.lua from here - https://github.com/breinhart/Corona-SDK-Tweet-Media/blob/master/utils/oAuth.lua
+multipartForm.lua from here - https://github.com/breinhart/Corona-SDK-Tweet-Media/blob/master/utils/multipartForm.lua
Basic Usage
-------------------------
@@ -37,6 +38,11 @@ twitter:authorise()
twitter:post( "Hello, world!" )
```
+##### Tweet a message with an image
+```lua
+twitter:post( "Check out my photo!", "image.png" )
+```
+
##### Check if the user is authorised.
```lua
print( twitter:isAuthorised() )
Please sign in to comment.
Something went wrong with that request. Please try again.