{"id":273,"date":"2014-01-16T18:10:19","date_gmt":"2014-01-16T17:10:19","guid":{"rendered":"http:\/\/globeotter.com\/blog\/?p=273"},"modified":"2014-01-25T17:33:01","modified_gmt":"2014-01-25T16:33:01","slug":"disqus-login-and-logout","status":"publish","type":"post","link":"http:\/\/globeotter.com\/blog\/disqus-login-and-logout\/","title":{"rendered":"Disqus Login and Logout in Android"},"content":{"rendered":"<p style=\"text-align: left;\">Disqus login and logout features as described in the previous <a title=\"blog entry\" href=\"http:\/\/globeotter.com\/blog\/disqus-android-code\/\" target=\"_blank\">blog entry<\/a> on <a title=\"Disqus\" href=\"http:\/\/disqus.com\/\" target=\"_blank\">Disqus<\/a> (http:\/\/globeotter.com\/blog\/disqus-android-code\/) do not work as intended in the latest updates. Currently if you followed the Code the login will stay busy and the page has to be refreshed. You can see the busy signal in the screenshot below. To get rid of it you have to change Activities and come back to the Disqus page (in which you are auto logged in). \u00a0After looking into it a bit, we found a nice work around for these issues.<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/globeotter.com\/blog\/wp-content\/uploads\/2014\/01\/Screenshot_2014-01-16-11-44-581.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-thumbnail wp-image-285\" title=\"Screenshot of Votter\" alt=\"Disqus login and logout created a busy signal in this screenshot\" src=\"http:\/\/globeotter.com\/blog\/wp-content\/uploads\/2014\/01\/Screenshot_2014-01-16-11-44-581-150x150.png\" width=\"150\" height=\"150\" \/><\/a><\/p>\n<p>If you would like to see how the code works you can look at our new App we made to Demo the functionality, <a title=\"The Daily Forum\" href=\"https:\/\/play.google.com\/store\/apps\/details?id=otter.forum\" target=\"_blank\">The Daily Forum<\/a> https:\/\/play.google.com\/store\/apps\/details?id=otter.forum<\/p>\n<p>The solution to the Disqus login and logout issues are contained in the WebViewClient in Android. It is not picking up the redirect and refreshing the page in the javascript. To address this we will need a new class that extends WebViewClient<\/p>\n<h2>MyWebViewClient.java<\/h2>\n<pre class=\"brush: plain; highlight: [20,24,28]; title: ; notranslate\" title=\"\">\r\npublic class MyWebViewClient extends WebViewClient {\r\n\r\nprivate String myUrl;\r\n public MyWebViewClient(String _myURL) {\r\n \/\/ TODO Auto-generated constructor stub\r\n myUrl=_myURL;\r\n\r\n }\r\n @Override\r\n public void onPageStarted(WebView view, String url, Bitmap favicon) {\r\n Log.i(&quot;page started&quot;, url);\r\n }\r\n\r\n@Override\r\n public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {\r\n Log.i(&quot;disqus error&quot;, &quot;failed: &quot; + failingUrl + &quot;, error code: &quot; + errorCode + &quot; &#x5B;&quot; + description + &quot;]&quot;);\r\n }\r\n\r\npublic void onPageFinished(WebView view, String url) {\r\n if(url.indexOf(&quot;logout&quot;)&gt;-1 || url.indexOf(&quot;disqus.com\/next\/login-success&quot;)&gt;-1 ){\r\n view.loadUrl(myUrl);\r\n\r\n }\r\n if(url.indexOf(&quot;disqus.com\/_ax\/twitter\/complete&quot;)&gt;-1||url.indexOf(&quot;disqus.com\/_ax\/facebook\/complete&quot;)&gt;-1||url.indexOf(&quot;disqus.com\/_ax\/google\/complete&quot;)&gt;-1){\r\n view.loadUrl(&quot;YOUR_URL\/login.php&quot;);\r\n\r\n }\r\n if(url.indexOf(&quot;YOUR_URL\/login.php&quot;)&gt;-1){\r\n view.loadUrl(myUrl);\r\n}\r\n}\r\n}\r\n<\/pre>\n<p>There are a few key features of this code. First it is listening for the Twitter,Facebook, and Google Plus login code. Your WebViewClient will now be looking for this URL &#8220;disqus.com\/_ax&#8221;. When it detects this we send it to a blank URL login.php. This login page does nothing, we only use it so we can detect that the 3rd party login was successful. Second, after we have either detected a 3rd party login (via login.php) or have been logged in via disqus (&#8220;disqus.com\/next\/login-success&#8221;) we refresh our URL (this is the URL passed in that your disqus page was using). Third, the logout code is quite simple. When a logout is detected simply refresh the url as well.<\/p>\n<p>Next we need to actually call this class. We will use the same Disqus.java class as the previous<a title=\"blog entry on Disqus\" href=\"http:\/\/globeotter.com\/blog\/disqus-android-code\/\" target=\"_blank\"> blog entry on Disqus<\/a>, but this time we will call MyWebViewClient<\/p>\n<h2>Disqus.java<\/h2>\n<pre class=\"brush: plain; highlight: [24]; title: ; notranslate\" title=\"\">&lt;\/pre&gt;\r\npublic abstract class Disqus extends Activity\r\n{\r\nprivate WebView webDisqus;\r\n\r\nprotected void onCreate(Bundle savedInstanceState)\r\n{\r\n\r\n\/\/set layout to disqus xml\r\nString url=&quot;http:\/\/\/showcomments.php?disqus_id=&quot;+insert disqus thread is here;\r\nsetContentView (R.layout.disqus);\r\n\r\nwebDisqus = (WebView) findViewById(R.id.disqus);\r\n \/\/set up disqus\r\n WebSettings webSettings2 = webDisqus.getSettings();\r\n\r\nwebSettings2.setJavaScriptEnabled(true);\r\n\r\nwebSettings2.setBuiltInZoomControls(true);\r\n\r\nwebDisqus.requestFocusFromTouch();\r\n\r\n\/\/set to the new WebViewClient Class\r\nwebDisqus.setWebViewClient(new MyWebViewClient(url));\r\n\r\nwebDisqus.setWebChromeClient(new WebChromeClient());\r\n\r\nwebDisqus.loadUrl(url);\r\n\r\n}\r\n\r\n}\r\n<\/pre>\n<p>We hope this helps if you were struggling with the Disqus login and logout in Android. Let us know if it works for you. If you get a chance check out the <a title=\"Daily Forum\" href=\"https:\/\/play.google.com\/store\/apps\/details?id=otter.forum\" target=\"_blank\">Daily Forum<\/a> and leave us a review!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Disqus login and logout features as described in the previous blog entry on Disqus (http:\/\/globeotter.com\/blog\/disqus-android-code\/) do not work as intended in the latest updates. Currently if you followed the Code the login will stay busy and the page has to be refreshed. You can see the busy signal in the screenshot below. To get rid [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,10,4,3],"tags":[],"class_list":["post-273","post","type-post","status-publish","format-standard","hentry","category-code-sample","category-daily-forum","category-disqus","category-votter","bubble-left"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Disqus Login and Logout in Android<\/title>\n<meta name=\"description\" content=\"Disqus login and logout out functions in Android don&#039;t work as intended. Described here is a workaround for some of the issues.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/globeotter.com\/blog\/disqus-login-and-logout\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Disqus Login and Logout in Android\" \/>\n<meta property=\"og:description\" content=\"Disqus login and logout out functions in Android don&#039;t work as intended. Described here is a workaround for some of the issues.\" \/>\n<meta property=\"og:url\" content=\"http:\/\/globeotter.com\/blog\/disqus-login-and-logout\/\" \/>\n<meta property=\"og:site_name\" content=\"GlobeOtter\" \/>\n<meta property=\"article:published_time\" content=\"2014-01-16T17:10:19+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-01-25T16:33:01+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/globeotter.com\/blog\/wp-content\/uploads\/2014\/01\/Screenshot_2014-01-16-11-44-581-150x150.png\" \/>\n<meta name=\"author\" content=\"ndgreen\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@globeotter\" \/>\n<meta name=\"twitter:site\" content=\"@globeotter\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"ndgreen\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"http:\/\/globeotter.com\/blog\/disqus-login-and-logout\/\",\"url\":\"http:\/\/globeotter.com\/blog\/disqus-login-and-logout\/\",\"name\":\"Disqus Login and Logout in Android\",\"isPartOf\":{\"@id\":\"http:\/\/globeotter.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/globeotter.com\/blog\/disqus-login-and-logout\/#primaryimage\"},\"image\":{\"@id\":\"http:\/\/globeotter.com\/blog\/disqus-login-and-logout\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/globeotter.com\/blog\/wp-content\/uploads\/2014\/01\/Screenshot_2014-01-16-11-44-581-150x150.png\",\"datePublished\":\"2014-01-16T17:10:19+00:00\",\"dateModified\":\"2014-01-25T16:33:01+00:00\",\"author\":{\"@id\":\"http:\/\/globeotter.com\/blog\/#\/schema\/person\/31fcba120c14e75da9dc801136a6ce5b\"},\"description\":\"Disqus login and logout out functions in Android don't work as intended. Described here is a workaround for some of the issues.\",\"breadcrumb\":{\"@id\":\"http:\/\/globeotter.com\/blog\/disqus-login-and-logout\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/globeotter.com\/blog\/disqus-login-and-logout\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/globeotter.com\/blog\/disqus-login-and-logout\/#primaryimage\",\"url\":\"http:\/\/globeotter.com\/blog\/wp-content\/uploads\/2014\/01\/Screenshot_2014-01-16-11-44-581.png\",\"contentUrl\":\"http:\/\/globeotter.com\/blog\/wp-content\/uploads\/2014\/01\/Screenshot_2014-01-16-11-44-581.png\",\"width\":1080,\"height\":1920},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/globeotter.com\/blog\/disqus-login-and-logout\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/globeotter.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Disqus Login and Logout in Android\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/globeotter.com\/blog\/#website\",\"url\":\"http:\/\/globeotter.com\/blog\/\",\"name\":\"GlobeOtter\",\"description\":\"GlobeOtter Development and News\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/globeotter.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"http:\/\/globeotter.com\/blog\/#\/schema\/person\/31fcba120c14e75da9dc801136a6ce5b\",\"name\":\"ndgreen\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/globeotter.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/80e4d0ae2e6044a1c6244388de171b5e5a488d004ffeb96dd914407ebef4b944?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/80e4d0ae2e6044a1c6244388de171b5e5a488d004ffeb96dd914407ebef4b944?s=96&d=mm&r=g\",\"caption\":\"ndgreen\"},\"sameAs\":[\"http:\/\/www.nathangreen.com\"],\"url\":\"http:\/\/globeotter.com\/blog\/author\/ndgreen\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Disqus Login and Logout in Android","description":"Disqus login and logout out functions in Android don't work as intended. Described here is a workaround for some of the issues.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/globeotter.com\/blog\/disqus-login-and-logout\/","og_locale":"en_US","og_type":"article","og_title":"Disqus Login and Logout in Android","og_description":"Disqus login and logout out functions in Android don't work as intended. Described here is a workaround for some of the issues.","og_url":"http:\/\/globeotter.com\/blog\/disqus-login-and-logout\/","og_site_name":"GlobeOtter","article_published_time":"2014-01-16T17:10:19+00:00","article_modified_time":"2014-01-25T16:33:01+00:00","og_image":[{"url":"http:\/\/globeotter.com\/blog\/wp-content\/uploads\/2014\/01\/Screenshot_2014-01-16-11-44-581-150x150.png","type":"","width":"","height":""}],"author":"ndgreen","twitter_card":"summary_large_image","twitter_creator":"@globeotter","twitter_site":"@globeotter","twitter_misc":{"Written by":"ndgreen","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"http:\/\/globeotter.com\/blog\/disqus-login-and-logout\/","url":"http:\/\/globeotter.com\/blog\/disqus-login-and-logout\/","name":"Disqus Login and Logout in Android","isPartOf":{"@id":"http:\/\/globeotter.com\/blog\/#website"},"primaryImageOfPage":{"@id":"http:\/\/globeotter.com\/blog\/disqus-login-and-logout\/#primaryimage"},"image":{"@id":"http:\/\/globeotter.com\/blog\/disqus-login-and-logout\/#primaryimage"},"thumbnailUrl":"http:\/\/globeotter.com\/blog\/wp-content\/uploads\/2014\/01\/Screenshot_2014-01-16-11-44-581-150x150.png","datePublished":"2014-01-16T17:10:19+00:00","dateModified":"2014-01-25T16:33:01+00:00","author":{"@id":"http:\/\/globeotter.com\/blog\/#\/schema\/person\/31fcba120c14e75da9dc801136a6ce5b"},"description":"Disqus login and logout out functions in Android don't work as intended. Described here is a workaround for some of the issues.","breadcrumb":{"@id":"http:\/\/globeotter.com\/blog\/disqus-login-and-logout\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/globeotter.com\/blog\/disqus-login-and-logout\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/globeotter.com\/blog\/disqus-login-and-logout\/#primaryimage","url":"http:\/\/globeotter.com\/blog\/wp-content\/uploads\/2014\/01\/Screenshot_2014-01-16-11-44-581.png","contentUrl":"http:\/\/globeotter.com\/blog\/wp-content\/uploads\/2014\/01\/Screenshot_2014-01-16-11-44-581.png","width":1080,"height":1920},{"@type":"BreadcrumbList","@id":"http:\/\/globeotter.com\/blog\/disqus-login-and-logout\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/globeotter.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Disqus Login and Logout in Android"}]},{"@type":"WebSite","@id":"http:\/\/globeotter.com\/blog\/#website","url":"http:\/\/globeotter.com\/blog\/","name":"GlobeOtter","description":"GlobeOtter Development and News","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/globeotter.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"http:\/\/globeotter.com\/blog\/#\/schema\/person\/31fcba120c14e75da9dc801136a6ce5b","name":"ndgreen","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/globeotter.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/80e4d0ae2e6044a1c6244388de171b5e5a488d004ffeb96dd914407ebef4b944?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/80e4d0ae2e6044a1c6244388de171b5e5a488d004ffeb96dd914407ebef4b944?s=96&d=mm&r=g","caption":"ndgreen"},"sameAs":["http:\/\/www.nathangreen.com"],"url":"http:\/\/globeotter.com\/blog\/author\/ndgreen\/"}]}},"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/globeotter.com\/blog\/wp-json\/wp\/v2\/posts\/273","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/globeotter.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/globeotter.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/globeotter.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/globeotter.com\/blog\/wp-json\/wp\/v2\/comments?post=273"}],"version-history":[{"count":30,"href":"http:\/\/globeotter.com\/blog\/wp-json\/wp\/v2\/posts\/273\/revisions"}],"predecessor-version":[{"id":312,"href":"http:\/\/globeotter.com\/blog\/wp-json\/wp\/v2\/posts\/273\/revisions\/312"}],"wp:attachment":[{"href":"http:\/\/globeotter.com\/blog\/wp-json\/wp\/v2\/media?parent=273"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/globeotter.com\/blog\/wp-json\/wp\/v2\/categories?post=273"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/globeotter.com\/blog\/wp-json\/wp\/v2\/tags?post=273"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}