机器人的WebView为Facebook的Like按钮机器人、按钮、Facebook、WebView

2023-09-12 01:34:22 作者:Memory丶旧城。

我试图让Facebook像Android中的WebView功能(项目规范不允许浏览器中打开,或任何的出应用程序的活动)。

I'm trying to make facebook like functionality in Android WebView (project specification does not allow browser opening, or any out of application activity).

所以,限制是它必须在web视图进行。我已经成功地使一个对话框,并APON用户点击按钮一样,它(的WebView)成功重定向(在同一视图),以Facebook的登录页。成功认证后,的WebView (在对话框中)被重定向到空白页与Facebook头。

So, restrictions are that it has to be done in WebView. I've managed to make it a dialog, and apon user's click like button, it (the WebView) redirects successfully (in the same view) to facebooks login page. After successful authentication, the WebView (in a dialog) is redirected to blank page with facebook header.

有趣的是,当用户离开的空白对话框,再点击等按钮,它的工作原理是完美的(像不像) - 它在某种程度上保持认证活跃。要解决该空白页,我试过/下使用:

Interestingly enough, when user leaves the blank dialog and click again on the like button it works like perfectly (like and unlike) - it somehow keeps authentication active. To resolve the blank page, I've tried/used following:

使用 WebViewClient shouldOverloadUrlForwarding 来保持整个过程中同样的WebView 对话框。 使用 WebChromeClient 来正确执行JavaScript的 - 没有它登陆后无法喜欢/不象。 使用尝试 setUserAgentString()来模拟其它浏览器,如Chrome或Firefox

试过了SSL证书的错误处理(在API级别8)(在 WebViewClient ) using WebViewClient and shouldOverloadUrlForwarding to keep whole process in same WebView dialog. using WebChromeClient to properly execute JavaScript - without it after login is not possible to like/unlike. tried using setUserAgentString() to simulate other browsers like Chrome or Firefox

tried the SSL Error certificate handling (in API level 8) (at WebViewClient)

@覆盖         公共无效onReceivedSslError(web视图来看,SslErrorHandler处理器,SslError错误){             handler.proceed();         }

@Override public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { handler.proceed(); }

使用(和这些所有可能的组合)

using (and all possible combination of these)

webView.getSettings()setAppCacheEnabled(真)。     webView.getSettings()setJavaScriptEnabled(真)。     。webView.getSettings()setJavaScriptCanOpenWindowsAutomatically(真);

webView.getSettings().setAppCacheEnabled(true); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);

试过了也坚持饼干 CookieSyncManager CookieManager 并进行手动处理。

Tried also persisting cookies with CookieSyncManager, CookieManager and manually handling.

所有这一切都是没有结果。我真的AP preciate 任何帮助!

All of this was with no result. I really appreciate any help!

推荐答案

要获得过去,你这样做的空白页:

To get past the blank page you do this:

 webview.setWebViewClient(new LikeWebviewClient(this));

 private class LikeWebviewClient extends WebViewClient {        
    @Override
    public void onPageFinished(WebView view, String url) {
        Log.d(TAG, "onPageFinished url: " +url);
        // Facebook redirects to this url once a user has logged in, this is a blank page so we override this
        // http://www.facebook.com/connect/connect_to_external_page_widget_loggedin.php?............
        if(url.startsWith("http://www.facebook.com/connect/connect_to_external_page_widget_loggedin.php")){
            String redirectUrl = getFacebookLikeUrl();
            view.loadUrl(redirectUrl);
            return;
        }
        super.onPageFinished(view, url);
    }
}