Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Twitter Plugin is Available Now!
Started by schroederapps Jul 17 2015 06:17 PM

42 replies to this topic
[TOPIC CONTROLS]
Page 2 of 2 1 2
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#26

schroederapps

[GLOBAL: userInfoPane.html]
schroederapps
  • Contributor

  • 466 posts
  • Corona SDK

@AdianWolf - d'oh! You are right. I had a typo in one section of my documentation where I listed "userName" instead of "screenName" in an example. It's been fixed. Thanks for helping find that!



[TOPIC: post.html]
#27

nevaben

[GLOBAL: userInfoPane.html]
nevaben
  • Observer

  • 14 posts
  • Enterprise

Hi Jason,

 

Thanks creating this plugin!  I having an issue where the twitter auth popup is incredibly off centered when you call twitter.login() outside of main.lua  You can only see 1/4 of the UI.  If I put the call in main.lua, it gets displayed just like in your demo.

 

I'm using Corona's composer/scenes to organize my UI.  Do you have a fix or workaround for this?  

 

Ben



[TOPIC: post.html]
#28

schroederapps

[GLOBAL: userInfoPane.html]
schroederapps
  • Contributor

  • 466 posts
  • Corona SDK

Hi @Ben:

 

I've never heard of this, and it's not something I've seen. There shouldn't be any reason why you can't use the plugin within a composer scene. Are you able to put together a small demo project that illustrates the problem? If so, I can try to find what might be causing it and/or adjust the plugin if something in the plugin is to blame. 

 

Thanks,

Jason



[TOPIC: post.html]
#29

nevaben

[GLOBAL: userInfoPane.html]
nevaben
  • Observer

  • 14 posts
  • Enterprise

@jason thanks for your reply.  I found the problem.  I changed the default anchor when building one of my UIs.

 

display.setDefault( "anchorX", 0 )
display.setDefault( "anchorY", 0 )


[TOPIC: post.html]
#30

schroederapps

[GLOBAL: userInfoPane.html]
schroederapps
  • Contributor

  • 466 posts
  • Corona SDK

Ah, that makes sense. Still - I appreciate you mentioning it here. I can explicitly set the anchorX and anchorY of the webView to .5 to avoid this in the future. :)



[TOPIC: post.html]
#31

mmk.verheijden

[GLOBAL: userInfoPane.html]
mmk.verheijden
  • Contributor

  • 203 posts
  • Corona SDK

Hi how can i trigger a function on a `TWITTER PLUGIN ERROR:` like :

 

if error then 

twitterbutionback()

end



[TOPIC: post.html]
#32

schroederapps

[GLOBAL: userInfoPane.html]
schroederapps
  • Contributor

  • 466 posts
  • Corona SDK

@mmk.verheijden: that's not a feature of the plugin at the moment, but it's a good idea. I'll add it to the "to-do" list and try to work it into a plugin update ASAP.



[TOPIC: post.html]
#33

mmk.verheijden

[GLOBAL: userInfoPane.html]
mmk.verheijden
  • Contributor

  • 203 posts
  • Corona SDK

thanks jason



[TOPIC: post.html]
#34

schroederapps

[GLOBAL: userInfoPane.html]
schroederapps
  • Contributor

  • 466 posts
  • Corona SDK

@mmk: I added the ability to listen for errors in your callback functions and respond accordingly. I just pushed the new version of the plugin, but it could be a few hours before it's actually on Corona's build servers for your use. Here's details on the new error handling functionality: http://www.jasonschroeder.com/2015/07/15/twitter-plugin-for-corona-sdk/#errorHandling

 

Essentially, callback functions previously only took one argument - now they take up to 3: the same old "response" (JSON string or Lua table), a "isError" boolean (nil if no error, true if there was an error), and "event" - a standard Corona networkResponse event table (nil if no error). Hope this helps - thanks for the suggestion!

 

@benchow: I also added a fix for the off-centered login webview if you changed the default anchorX and anchorY values. Thanks again for reporting that!



[TOPIC: post.html]
#35

AidanWolf

[GLOBAL: userInfoPane.html]
AidanWolf
  • Enthusiast

  • 92 posts
  • Corona SDK

@mmk thank you for asking.

 

@schroederapps thank you for implementing this feature, it was a must have, especially when hitting rate limits or getting blocked by the api (unknowingly for a period of time.) 

 

If any of you are interested, I can post my function for defaulting to the native social plugin in an error situation.



[TOPIC: post.html]
#36

guiller.c.ramos

[GLOBAL: userInfoPane.html]
guiller.c.ramos
  • Observer

  • 3 posts
  • Corona SDK

trying to create a demomy code below
 

local myRectangle = display.newRect( display.contentCenterX, display.contentCenterY, display.actualContentWidth, display.actualContentHeight )
 
local twitter = require ("plugin.twitter")
twitter.init("gWxZVU4RW56ss2VIGnoiem0M2", "fPd7s0raTVmE4YxqvLzR6wT4ZEyPuPuefgEuWGguwzgf8dhL4f")
 
local myText = display.newText( "Twitter Test App", display.contentCenterX, 5, native.systemFontBold, 12 )
myText:setFillColor( 1, 0, 0.5 )
 
local widget = require( "widget" )
 
--Log In
local function onSuccess()
    print("aa")
print("Twitter user " .. twitter.user.screenName .. " successfully logged in!")
myText:removeSelf( )
myText = nil
myText = display.newText( "Twitter user " .. twitter.user.screenName .. " successfully logged in!" , display.contentCenterX, 5, native.systemFontBold, 12 )
myText:setFillColor( 1, 0, 0.5 )
end
 
local function onFail()
print("Twitter login attempt failed or was cancelled by user.")
myText:removeSelf( )
myText = nil
myText = display.newText( "Twitter login attempt failed or was cancelled by user." , display.contentCenterX, 5, native.systemFontBold, 12 )
myText:setFillColor( 1, 0, 0.5 )
end
 
local function logInEvent( event )
    if ( "ended" == event.phase ) then
        print( "Button was pressed" )
        twitter.login(onSuccess, onFail)
    end
end
 
local button1 = widget.newButton(
    {
        left = 100,
        top = 100,
        id = "button1",
        label = "Twitter login",
        onEvent = logInEvent
    }
)
 
 
 
---------------
ends up with

ERROR: Runtime error
?:0: attempt to concatenate field 'screenName' (a nil value)
stack traceback:
[C]: ?
?: in function '?'
?: in function <?:164>



[TOPIC: post.html]
#37

guiller.c.ramos

[GLOBAL: userInfoPane.html]
guiller.c.ramos
  • Observer

  • 3 posts
  • Corona SDK

ive been using the twitter demo app to returns same error



[TOPIC: post.html]
#38

AppDeveloperGuy

[GLOBAL: userInfoPane.html]
AppDeveloperGuy
  • Enthusiast

  • 36 posts
  • Corona SDK

Hi Jason,

 

I just wanted to say that I've been working with your Twitter plugin - https://marketplace.coronalabs.com/plugin/twitter - for the last couple of days and wanted to say a big thank you for your contribution to the Corona community! It's been a real time saver and it's well worth the $3 asking price on the marketplace (if not more)!

 

With that, I have a request or two... hope you don't mind... :)

 

  1. The method twitter.tweet() successfully returns the id of the newly posted tweet for a simple status update but does not when imageFile is provided - even though the tweet and image file have both been sent successfully. Is this something that can be corrected please?
     
  2. I see that the endpoint "statuses/update_with_media" has been deprecated in favour of using "media/upload" then "statuses/update" but I was unable to achieve this myself using the twitter.request() method. Would it be possible to provide a code sample please on how this might be achieved with the plugin (especially "Ensure the POST is a multipart/form-data request")?
     
  3. The demo project didn't work for me I'm afraid - the buttons never responded - so I decided to dig in to the code. I wonder, would it be possible to provide a console-only demo where one can just comment/uncomment methods they want to test and configure please? I found mixing these methods with presentation logic a little confusing.

 

Again, many thanks for such a great plugin and I look forward to seeing it thrive on the marketplace!

 

Thanks,

 

AppDevGuy



[TOPIC: post.html]
#39

schroederapps

[GLOBAL: userInfoPane.html]
schroederapps
  • Contributor

  • 466 posts
  • Corona SDK

@AppDevGuy: thanks for the kind words! I'll look into your requests. At first glance, #1 (returning the ID) seems easily doable. #2 is a lot trickier, as handling multipart form data is not the easiest thing and it's been a while since I've dealt with it. I'll see what I can do, but as I recall, I opted to use the update_with_media endpoint for my convenience function precisely because getting media/upload to work from Corona was not the simplest of operations. For #3, if I'm being honest, I'm not very likely to put together another demo project anytime soon - I downloaded a copy, plugged in a valid API key/secret pair and it just worked for me, on both Mac and Windows. Are you using a recent daily build of the SDK? If you need basic code samples, there are code snippets for each method in the documentation at http://twitter.plugin.jasonschroeder.com.

 

Stay tuned for a fix on that first request for certain, though. :)


  • AppDeveloperGuy likes this

[TOPIC: post.html]
#40

AppDeveloperGuy

[GLOBAL: userInfoPane.html]
AppDeveloperGuy
  • Enthusiast

  • 36 posts
  • Corona SDK

@AppDevGuy: thanks for the kind words! I'll look into your requests. At first glance, #1 (returning the ID) seems easily doable. #2 is a lot trickier, as handling multipart form data is not the easiest thing and it's been a while since I've dealt with it. I'll see what I can do, but as I recall, I opted to use the update_with_media endpoint for my convenience function precisely because getting media/upload to work from Corona was not the simplest of operations. For #3, if I'm being honest, I'm not very likely to put together another demo project anytime soon - I downloaded a copy, plugged in a valid API key/secret pair and it just worked for me, on both Mac and Windows. Are you using a recent daily build of the SDK? If you need basic code samples, there are code snippets for each method in the documentation at http://twitter.plugin.jasonschroeder.com.

 

Stay tuned for a fix on that first request for certain, though. :)

 

That's great, thanks Jason! :)

 

#1 : Would it also be possible to return the full Twitter response too I wonder? As though one might have called the .request method themselves? Perhaps have a third property - a "details" table - in the response along with id and text that contains this. That would be very useful if possible.

 

#2 : Yeah, I had a quick go myself with network.request and I could see it would require more work than the time I have to spare at the moment. Good luck with it! Hopefully "update_with_media" will be with us for a little while longer yet.

 

#3 : Hmm... I thought I was. I'll try again. As for samples, it might be useful if we users share code snippets on here as we dig through the Twitter api and put together custom requests. I'll be more than happy to do that once I experiment beyond basic usage.

 

Thanks again, Jason. Yours is a vital plugin for Twitter engagement and I do hope it receives the support and recognition it deserves.



[TOPIC: post.html]
#41

schroederapps

[GLOBAL: userInfoPane.html]
schroederapps
  • Contributor

  • 466 posts
  • Corona SDK

@appdevguy: I'm unable to reproduce the issue you reported - tweeting using twitter.tweet, both with and without an image attached, is resulting in a proper response table getting passed to my listener function, including the tweet's ID. This is using my sample Twitter demo. If you can zip up a small test case that makes it possible to reproduce the specific issue you mentioned, I'm happy to take a look, but at the moment I'm unable to fix it because I'm unable to reproduce it.

 

As for adding the full response, I'll look into it, but in general my goal was to strip that away from the convenience functions, to make them as simple as possible for novice users. If you need the full JSON response, you can always use twitter.request() - that's all that twitter.tweet() is anyway: just a wrapper around a twitter.request() call. :)



[TOPIC: post.html]
#42

Falcon777

[GLOBAL: userInfoPane.html]
Falcon777
  • Contributor

  • 406 posts
  • Corona SDK

Anyone who used this plugin knows if it is necessary for the user to login before the app can make a twitter.request() call?



[TOPIC: post.html]
#43

schroederapps

[GLOBAL: userInfoPane.html]
schroederapps
  • Contributor

  • 466 posts
  • Corona SDK

Hi @Falcon777:

 
Yes, unfortunately Twitter’s REST API won’t let you make unauthenticated requests, at least last time I checked.
 
You can get around this by manually populating the twitter.user table, which contains the token data necessary to make requests after a user logs in. But if a lot of people use your app, using the same token for all those users will cause errors because Twitter limits the number of requests a single token can make in a short period of time.
 
If you want to retrieve the necessary token data, just log in yourself and then iterate over the twitter.user table like so:
 
for k,v in pairs(twitter.user) do
  print(tostring(k) .. “: “ .. tostring(v) end
end
Then add code to your app that manually populates that table with those values at launch. But proceed with caution, and I’d personally advise against this. If you run into Twitter’s rate limit too frequently, they could take action against your app for spamming, which could cause a whole slew of headaches.
 
Best,
Jason



[topic_controls]
Page 2 of 2 1 2
 
[/topic_controls]