0

Rails 3 アプリケーションで特定の URL に与えられた Facebook の Likes、Google の +1、Diggs、StumbleUpon からの Stumbles、および Tweets をカウントする必要があります。

Rails にチュートリアル、API、またはデモはありますか?

4

1 に答える 1

0

についてfacebook likes countは、google +1 count

URLに応じてカウントを見つけるために、次のヘルパーを作成します

  #Ref:- http://developers.facebook.com/docs/reference/plugins/like/
  def facebook_like_count(url, id)
    js = <<-JAVASCRIPT
      <div id="#{id}">
        <img src='/images/facebook_login.png'/>
      </div>
      <script>
        jQuery(window).load(function() {
          var query = FB.Data.query('select like_count from link_stat where url="#{url}"');
          query.wait(function(rows){
            jQuery("##{id}").append((typeof(rows[0]) === "undefined") ? "<br/>0" : "<br/>"+rows[0].like_count)
          });
        });
      </script>
      JAVASCRIPT
      js.html_safe
  end

  def tweets_count(url, id)
    js = <<-JAVASCRIPT
      <div id="#{id}">
        <img src="/images/share-twitter.png" />
      </div>
      <script>
        jQuery(window).load(function() {
          jQuery.getJSON('http://feeds.delicious.com/v2/json/urlinfo/data?url='+"#{url}"+'&amp;callback=?',
            function(data) {
              jQuery('##{id}').append((typeof(data[0]) === "undefined") ? "<br/>0" : "<br/>"+data[0].total_posts);
          });
        });
      </script>
      JAVASCRIPT
      js.html_safe
  end

  #Ref:- https://developers.google.com/+/plugins/+1button/#plusonetag-parameters
  def google_plus_one_count(url, id)
    js = <<-JAVASCRIPT
      <div id="#{id}">
        <g:plusone href="#{url}" annotation="bubble"></g:plusone>
      </div>
      <script type="text/javascript">
        jQuery(window).load(function() {
        window.___gcfg = {
          lang: 'en-US'
        };

        (function() {
          var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
          po.src = 'https://apis.google.com/js/plusone.js';
          var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
        })();
        });
      </script>
      JAVASCRIPT
      js.html_safe
  end
于 2012-12-12T05:50:05.267 に答える