Monday, October 31, 2011

Adding Facebook moderated comments to your website and making facebook comments indexable PHP code


Facebook plugin allows  you to add a comment section to your webpages. This plugin accepts logins from Facebook, Yahoo, AOL etc. The code to add the plugin can be found here.


Adding the code that you get from the link above is straight forward, however there are a few issues that you will need to address to get it working properly on your website. Recently I addressed these and found a working solution.

Issue No. 1 - Separate comments for each webpage for your website


Facebook records comments for each "data-href" URL that is provided in the plugin code. So the trick is to modify this "data-href" field for each web page of your website. Of course doing it manually can be very cumbersome. So I've written following JS code that does some basic cleanup on the URL and then plugs this "cleaned up" URL in the "data-href" field.

----------------------------------------------------------

<script type="text/javascript">
     <!--
      var strng = location.href;
      var splits = strng.split("&");
      var splt2 = splits[0].split("?fb_comment_id");
      document.write('<div class="fb-comments" data-href="');
      document.write(splt2[0]);
      document.write('" data-num-posts="4" data-width="600"></div>');

      // -->
</script>

---------------------------------------------------------




Issue No. 2 - Making comments Moderatable

add the following code after the head tag in your HTML. Replace the content field ^^'s with your APP ID



---------------------------------------------------------
<meta property="fb:app_id" content="^^^^^^^^^^^^"/>
---------------------------------------------------------

After you have added this code. You can go to this page to moderate comments.


Issue No. 3 - Making Facebook Comments Indexable


This is very important step for SEO since Facebook comments are pulled from Facebook API's within a JS and are not indexed by Search engines, which is a big hit to SEO. Remember the same URL "cleanup" step to do here as the first step when you plugged the cleaned up URL in the "data-href" field. Following PHP code uses cUrl code to pull the comments data from Facebook and displays it on the webpage.

One issue with this presenting of comments data on your webpage is that "How do you show it on your page". Answer to this I dont know. One straight forward option is to hide it under "div hidden". But that is questionable choice. Since Search Engines do not like hidden text on your webpages. In the case of hiding Facebook comments data on you webpage is a genuine need, since the comments are already shown to the user from the plugin code, BUT that is something search engine is unaware of. Hiding text can get your website unindexed from search engine, sort of blacklisting.

Another issue with following code is that it bypasses security. cUrl code disables SSL options to be able to get this working. You may want to search a bit more and see if you can get SSL part working as well that is without disabling options.

---------------------------------------------------------
<?php


$ch = curl_init();
$timeout = 5;


$url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];


//echo $url;
//echo ("<br/>");
$pieces = explode("&",$url);
//echo $pieces[0];
//echo ("<br/>");


$splits = explode("?fb_comment_id",$pieces[0]);
//echo $splits[0];
//echo ("<br/>");


$request_url ="https://graph.facebook.com/comments/?ids=".$splits[0];


//echo $request_url;
//echo ("<br/>");


curl_setopt($ch,CURLOPT_URL,$request_url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);


$data = curl_exec($ch);
//    print "<div style:visibility="hidden">";
    print "<PRE>";
    print_r($data);
    print "</PRE>";
//    print "</div>";
curl_close($ch);
?>
----------------------------------------------------------



In case I've missed anything I'll revisit the post, after checking any comments. Of course the disclaimer - Use all of this information at your own risk.


Sunday, October 23, 2011

Reliance Netconnect+ very bad service in Bangalore

Reliance Netconnect+ is a scam. They claim it to be a broadband and the charges are at par with other broadband services like DSL etc. But the speeds in Bangalore are only in the range of 1-10 Kbps which is not sufficient for even email checking and browsing.

On top of this, there are frequent disconnects. You cant even read news properly without getting disconnected, multiple times. Really annoying.

I had given them a request to change my plan to prepaid from postpaid, since I had stopped using it. After two months and multiple phone calls, they have still not changed my plan to prepaid. It is still in post paid and despite not using it, I have already received two bills. First one I was asked to pay saying after this there will not be any bill. But there is a second postpaid bill which is sent and I am being called to pay it as well.

What a scam, bad service, and bills are being sent without using the service. Two months back if they had changed it to prepaid, I wont be getting these bills but they simply wont do it.

Over all very bad experience.

Friday, October 14, 2011

Sorry, we did not find a suitable Google Analytics account for ... The solution

I had the same problem. Actually Ad Planner and Analytics were showing two different versions of my site's url. For example if i own toi.com

Analytics: www.toi.com
Ad Planner: toi.com (without the preceding www.)

I removed the www. from the url at Analytics by clicking on the pencil icon to the right of the url and it started working fine. Turns out, both the urls at both Analytics and Ad Planner must have the identical characters.