Twitter Web Intents inside iOS/Android Webview - any Redirect/Callback URL?


#1

Twitter Web intents provides convenient JS lib to allow the user to tweets from an external website.

  <script type="text/javascript" src="//platform.twitter.com/widgets.js"></script>
  <p><a href="https://twitter.com/intent/tweet?text=textToTweet">link</a></p>

This works great on mobile browser by openining a new window with twitter’s textarea for the user to submit its tweet. Once tweeted the popup close and the user is back on the original page.

However in the context of a native app using webviews (a good example is facebook webview) the flow seems to be broken. Rather than opening a popup or new window it redirect the current webview to twitter page. From there there is no way for the user go back to the original page.

Is there any parameter that i could pass to https://twitter.com/intent/tweet for twitter to redirect back to the user page after tweeting or canceling?

This is essentially a repost of this StackOverflow question which has gone unanswered - http://stackoverflow.com/questions/11183946/twitter-web-intents-inside-ios-android-webview-any-redirect-callback-url. Curious if there are any updates on this?


#2

A web intent URL may be opened by the Twitter app if installed on the device, taking the viewer into what’s likely a logged-in composer experience to author the Tweet. Is this in-app composer view the “twitter page” you are referencing?


#3

Hi Niall - thanks for your quick response!

I’ve included some screenshots to explain more clearly what I mean. If I open a webpage using an app which uses a WebView to display external links (in my example I used the Feedly app), then if I use the Twitter Intent dialog I have no way of returning to the website I was browsing once I have tweeted.

For example, I open the following web page in the Feedly app:

I then tap the twitter button to share on twitter

Then once I share, I’m now trapped on the success page of the tweet process

with no way to return to the article I was reading, apart from closing and reopening the webview. This is a problem when the webpage I’m viewing contains some state e.g. in a Single Page Application when sharing is the final step.

The default behaviour in Safari is to open the Twitter app which would be fine as an alternative as then I could use the "Back To … " button in iOS 9 to return to where I was.

Thanks for your help.


#4

Hi!

Short answer to your question: There is no callback URL system in intents. The standard behavior in Safari is that the page is opened using window.open, which then allows the pop-up window to close itself after the action is completed (it either auto-closes, or displays a “close” button to do this.) However, most regular WebViews in apps do not implement support for multiple pages, so the default behavior is that a window.open call will just replace the current page (and, irritatingly, also won’t necessarily push that page onto the history stack for pressing “Back”.)

You have a few options to improve the experience:

  1. Add handling to your webview for window.open and window.close, which should allow the Intent to dismiss itself upon completion.
  2. In your bespoke webview, listen for navigation to a URL path pattern like /intent/*/complete, which you can use as a cue to close the webview, since intents redirect to that view once the action is done.
  3. If this is all UI under your control, consider using TwitterKit, make use of the native iOS Twitter Composer UI instead of the Web Intent, which is also convenient and allows the user to use their system login credentials.

Hope that helps!

Ben


#5

Hi Ben,

Thanks for your reply. Unfortunately, we’re (mostly) makers of websites rather than apps so at the mercy of 3rd party developers in this case. It’s slightly frustrating in that for most of our websites we see the number one browser as Safari (In App) meaning that most of our users lose this context whenever they share on Twitter.

I understand that your webview doesn’t cause this problem, however, so your options may be limited. However, we would be interested in any developments in this area.

Thanks for your help


#6