6

私はウェブサイト用のAndroidアプリを開発しています。このWebサイトは、コメントサービスのDisqusをサポートしています。私のアプリケーションでも同じことをサポートしたいと思います。DisqusドキュメントからAPIを入手しましたが、それでもアプリケーションにAPIを統合する方法がわかりません。実装を理解するのを手伝ってください。誰かがDisqusコメントサービスをAndroidアプリに統合していますか?

4

3 に答える 3

10

私のウェブサイトが私のAndroidアプリにリンクされたスレッドをdisqusするのと同じ問題に遭遇しました。興味があれば、ちょっとしたウォークスルーを書きました。以下のウォークスルーにリンクします。基本的に、Androidアプリでは、WebViewを使用し、disqus識別子を取得できる別のphpファイルを使用します。

http://globeotter.com/blog/disqus-android-code/

于 2012-12-27T02:49:43.630 に答える
5

ndgreenに感謝します。あなたのアイデアを見て、私はPHPファイルの必要性なしに何か違うものを作成しました: https ://gist.github.com/bichotll/5563926

このスクリプトは、単純な関数からhtmlを作成し、thをロードするだけです。

于 2013-05-12T15:33:41.377 に答える
0

このコードを使用できます:Googleログインが機能しています。Facebookはまだテストしていません。

static void setupDisqus(Context context, WebView disqus) {
    try {
        String URL = ""; // URL must be unique like identifier! Because Disqus, is using the url instead of identifier.
        String identifier = "";
        String shortName = "";
        String commentsUri = "https://captainsp.github.io/disqus_comments_dark_gray.html?" + "shortname=" + shortName +
                "&url=" + URLEncoder.encode(URL, "UTF-8") +
                "&title=" + URLEncoder.encode("Comments", "UTF-8") +
                "&identifier=" + URLEncoder.encode(identifier, "UTF-8");

        /*
         * You can use this colors in my Github Account:
         * disqus_comments_dark_gray.html
         * disqus_comments.html
         * disqus_comments_dark.html
         *
         *
         */

        disqus.setWebViewClient(new WebViewClient() {
            @Override
            public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
                new Handler().postDelayed(disqus::reload, 2000); // Reload Comments
                super.onReceivedError(view, request, error);
            }
        });
        CookieManager.getInstance().setAcceptThirdPartyCookies(disqus, true); // Accept Cookies to login (If you forget this part users need to login every single time)
        disqus.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); // Google / Facebook Login
        disqus.getSettings().setSupportMultipleWindows(true); // Google / Facebook Login
        CookieManager.getInstance().setAcceptCookie(true); // Accept Cookies to login 2
        disqus.setWebChromeClient(new WebChromeClient() {
            @SuppressLint("SetJavaScriptEnabled")
            @Override
            public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
                WebView newWebView = new WebView(context); // Create new WebView
                WebSettings webSettings = newWebView.getSettings();
                webSettings.setJavaScriptEnabled(true);
                webSettings.setUserAgentString(webSettings.getUserAgentString().replace("; wv", "")); // Hide WebView User Agent
                final Dialog dialog = new Dialog(context); // Create Dialog
                dialog.setContentView(newWebView);
                dialog.show();
                CookieManager.getInstance().acceptThirdPartyCookies(newWebView);
                newWebView.setWebViewClient(new WebViewClient());

                newWebView.setWebChromeClient(new WebChromeClient() {
                    @Override
                    public void onCloseWindow(WebView window) {
                        dialog.dismiss(); // Close the dialog after logged in
                    }
                });

                ((WebView.WebViewTransport) resultMsg.obj).setWebView(newWebView);
                resultMsg.sendToTarget();

                return true;
            }
        });
        disqus.getSettings().setJavaScriptEnabled(true); // Enable JavaScript
        disqus.getSettings().setAppCacheEnabled(true);
        disqus.getSettings().setDomStorageEnabled(true);
        disqus.loadUrl(commentsUri);
    } catch (Exception e) {
        e.printStackTrace();
    }

}

最初に新しいWebViewを作成するか、次のコマンドでそれを見つけますfindViewById(R.id.webView); 。次に、WebViewにDisqusをセットアップします。setupDisqus(this,webView);

詳細情報:https ://help.disqus.com/en/articles/1717165-javascript-embed-in-native-apps

于 2021-01-01T14:29:30.633 に答える