我想在我的Android应用中添加disqus。 我跟踪并找到了用id和短名称显示disqus注释的代码。 但我无法找到添加密钥和公钥的文档。然后继续前进。
已经在Disqus中注册,获得了我的私钥和公钥。 现在我需要知道,
1. Where to add the keys to the app.
2. How do I create id mapping to a particular page(activity/fragment).
3. Where am I supposed to give the short name?
答案 0 :(得分:4)
@ndgreen,不再工作了!跨域安全性提供加载外部JS。我们现在必须这样做:
String htmlComments = getHtmlComment("idPost", "youriddisqus");
yourWebView.loadDataWithBaseURL("http://youriddisqus.disqus.com/", htmlComments, "text/html", "UTF-8", "");
public String getHtmlComment(String idPost, String shortName) {
return "<html><head></head><body><div id='disqus_thread'></div></body>"
+ "<script type='text/javascript'>"
+ "var disqus_identifier = '"
+ idPost
+ "';"
+ "var disqus_shortname = '"
+ shortName
+ "';"
+ " (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;"
+ "dsq.src = '/embed.js';"
+ "(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })();"
+ "</script></html>";
}
瞧!
答案 1 :(得分:2)
答案 2 :(得分:0)
<div id="disqus_thread"></div>
<script>
var disqus_config = function () {
this.page.url = 'linkOFPage'
this.page.identifier = 'page_identifier';
};
(function() { // DON'T EDIT BELOW THIS LINE
var d = document, s = d.createElement('script');
s.src = '//forumName.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
</script>
然后将活动作为 -
webDisqus = (WebView) findViewById(R.id.disqus);
//set up disqus
WebSettings webSettings2 = webDisqus.getSettings();
webSettings2.setJavaScriptEnabled(true);
webSettings2.setBuiltInZoomControls(true);
webDisqus.requestFocusFromTouch();
String htmlComments = getHtmlComment(url, "forumName");
webDisqus.setWebViewClient(new MyWebViewClient(htmlComments,"text/html", null, ""));
webDisqus.setWebChromeClient(new WebChromeClient());
webDisqus.loadDataWithBaseURL("http://forumName.disqus.com/",htmlComments,"text/html","UTF-8","");
public String getHtmlComment(String idPost, String shortName) {
return "<html><head></head><body><div id='disqus_thread'></div></body>" + "<script type='text/javascript'>"
+ "var disqus_identifier = '" + idPost + "';" + "var disqus_shortname = '" + shortName + "';"
+ "var disqus_config = function () {this.page.identifier='" + idPost + "';" + "}" + ";"
+ " (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;"
+ "dsq.src = '/embed.js';"
+ "(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })();"
+ "</script></html>";
}
自定义Web视图客户端文件 -
public class MyWebViewClient extends WebViewClient
{
private String html_comments, sType, obj, sMyURL;
public MyWebViewClient(String htmlComments, String string, String object, String URL) {
// TODO Auto-generated constructor stub
html_comments = htmlComments;
sType = string;
obj = object;
sMyURL = URL;
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
Log.i("page started", url);
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Log.i("disqus error", "failed: " + failingUrl + ", error code: " + errorCode + " [" + description + "]");
}
public void onPageFinished(WebView view, String url) {
if (url.indexOf("logout") > -1 || url.indexOf("disqus.com/next/login-success") > -1) {
view.loadDataWithBaseURL("http://forumName.disqus.com/", html_comments, "text/html", "UTF-8", null);
}
if (url.indexOf("disqus.com/_ax/twitter/complete") > -1 || url.indexOf("disqus.com/_ax/facebook/complete") > -1
|| url.indexOf("disqus.com/_ax/google/complete") > -1) {
view.loadUrl("file:///android_res/raw/login.php");
}
if (url.indexOf("file:///android_res/raw/login.php") > -1) {
view.loadDataWithBaseURL("http://forumName.disqus.com/", html_comments, "text/html", "UTF-8", null);
}}
最后我在res中创建了一个原始文件夹,并通过名称login.php
保存了ablank文件 希望这有助于某人。 感谢globe totter