Phonegap / Cordova ChildBrowser won't run Twitter web intents (SSL?)

大憨熊 提交于 2019-12-11 07:47:14

问题


I'm trying to integrate Twitter sharing functionality into my Android PhoneGap application, and rather than re-implement the controls to shorten URLs and track tweet length, I thought I'd use their premade web intents at https://twitter.com/intent/...

So I'm trying to launch a URL like https://twitter.com/intent/tweet?text=Hello in a ChildBrowser window, so that I can let Twitter's interface take over. The user could sign in with their credentials, and once they're signed in, the text from the URL params would appear in the Tweet box.

It won't work. When I use http://twitter.com/intent/... instead of https://twitter.com/intent/... , ChildBrowser displays the sign-in screen, but as soon as the user submits their credentials, the screen goes white. I suspect this is because Twitter switches over to HTTPS.

I confirmed that this was the case by trying a simple window.open instead of window.plugins.childBrowser.showWebPage. I have no problems with HTTP / HTTPS when using the native browser on Android. However, the native browser prompts me to accept an unverified security certificate. I suspect this is the problem with ChildBrowser - it doesn't know how to handle that prompt.

Using the native browser popover simply isn't an option: the user needs to be able to exit the process after hitting 'Tweet' or 'Follow', etc., but the 'back' button on the Android device simply moves the history one step backward to the POST action for their intent. Then, it re-launches the app from scratch, instead of returning you to the original state.

How can I configure ChildBrowser / my Android Phonegap application to override SSL issues on Twitter, so that I can run web intents in Childbrowser?

The relevant code is:

base="https://twitter.com/intent/tweet?text="; 
URL=base+encodeURIComponent("it works!"); 

// works, but asks to accept a certificate
window.open(URL);

// blank white page
window.plugins.childBrowser.showWebPage(URL, { showLocationBar: true });

My cordova.xml file has whitelists configured as such:

<access origin="http://127.0.0.1*"/> <!-- allow local pages -->

...which I don't suspect should be a problem. However, a basic test of swapping origin=".*" yielded no change in behaviour.

I've also examined the HTTP and HTTPS headers for the Twitter intent landing pages. There doesn't appear to be anything out of line - they're identical, except for the Strict-Transport-Security header for HTTPS, which works elsewhere (e.g. Github).

Please help!


回答1:


The ChildBrowser is not bound by the whitelist. The whitelist is only used to keep the main PhoneGap app from running code outside of trusted domains.

I'm confident if you go get the latest ChildBrowser code from Android you won't have run into this problem anymore. We've made some changes recently that make it more robust.

Also, Libby has a good tutorial integrating Twitter and the ChildBrowser.

http://www.mobiledevelopersolutions.com/home/start/twominutetutorials/tmt5p1



来源:https://stackoverflow.com/questions/10865454/phonegap-cordova-childbrowser-wont-run-twitter-web-intents-ssl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!