1
votes

So I am following the twitter api tutorial here: (http://coronalabs.com/blog/2013/02/11/using-the-ios-built-in-twitter-feature/) and it works and posts normally. However after I click send, twitter closes and then loads back again automatically and displays an error message on device saying " duplicate error, cannot send tweet"

How can I stop twitter loading up immediately after I post first message and stop the duplicate tweet error?

function tweetCallback( event )
  transition.to(twitterbtn, {time=50, y=display.contentCenterY +120 })
    if ( event.action == "cancelled" ) then
      print( "User cancelled" )
    else
      native.showPopup( "twitter", options )
      print( "Thanks for the tweet!" )
    end
end

--

local options = {
    message = " I scored "  .. utils.highscore ..  " Miles ",
    listener = tweetCallback
}

Button ID settings

function buttonPressed(event)
    local id = event.target.id
    if id == "menu" then transition.to(homebtn, {time=50, y=display.contentCenterY + 124, onComplete=gameReady})
    elseif id == "tweet" then transition.to(twitterbtn, {time=50, y=display.contentCenterY + 124,  onComplete=tweetCallback})
    elseif id == "reload" then transition.to(reloadButton, {time=50, y=display.contentCenterY + 124, onComplete=reloadGame})

    end

    return true
  end 

  homebtn.id = "menu"
  twitterbtn.id = "tweet"
  facebookButton.id = "reload"
  homebtn:addEventListener("tap", buttonPressed)
  twitterbtn:addEventListener("tap", buttonPressed) 
  reloadButton:addEventListener( "tap", buttonPressed )
1

1 Answers

0
votes

Remove the native.showPopup( "twitter", options ) from the tweetCallBack function. This function is used to handle callBacks after a tweet has been send or cancelled.

You need to call the native.showPopup( "twitter", options ) from some other event, ex. a button click.

ADDED:

local  function tweetThis(obj)
    local options = {
        message = " I scored "  .. utils.highscore ..  " Miles ",
        listener = tweetCallback
    }

    native.showPopup( "twitter", options )
end

function buttonPressed(event)
    local id = event.target.id
    if id == "menu" then transition.to(homebtn, {time=50, y=display.contentCenterY + 124, onComplete=gameReady})
    elseif id == "tweet" then transition.to(twitterbtn, {time=50, y=display.contentCenterY + 124,  onComplete=tweetThis})
    elseif id == "reload" then transition.to(reloadButton, {time=50, y=display.contentCenterY + 124, onComplete=reloadGame})

    end

    return true
  end 

  homebtn.id = "menu"
  twitterbtn.id = "tweet"
  facebookButton.id = "reload"
  homebtn:addEventListener("tap", buttonPressed)
  twitterbtn:addEventListener("tap", buttonPressed) 
  reloadButton:addEventListener( "tap", buttonPressed )