0

drupal では、私たちのページのいいね! の数を表示したいと考えています。

facebook グラフ ユーティリティを使用できることは知っていますが、html の「スニペット」に正しいコードを挿入する方法がわかりません。誰でもアイデアはありますか?

4

3 に答える 3

1

Drupal には詳しくありませんが、HTML + JS を介して行う方法は次のとおりです。

window.fbAsyncInit = function() {
    FB._https = true;
    // init the FB JS SDK
    FB.init({
      appId      : YOUR APP ID, // App ID from the App Dashboard
      channelUrl : 'channel.html', // YOUR CHANNEL HTML
      status     : true, 
      cookie     : true, 
      xfbml      : true 
    });

    getPage();

};
  (function(d, debug){
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all" + (debug ? "/debug" : "") + ".js";
     ref.parentNode.insertBefore(js, ref);
   }(document, /*debug*/ false))


getPage = function() {
    var pageID = 'http://google.com';  //put your site here
    var pageUrl = 'https://graph.facebook.com/'+pageID;
    FB.api(pageUrl, 'get', function(response) {
            alert( response.likes )
    });
}
于 2013-03-17T22:39:47.047 に答える
0

次の PHP スニペットは、ブロックまたは PHP の使用が許可されているその他の場所で使用できます。

$graph    = 'https://graph.facebook.com/< your facebook page id>/?fields=likes';
$response = file_get_contents($graph);
$json     = json_decode($response);
try {
  if (!isset($json->likes)) {
    throw new Exception('Like count not found in facebook graph object');
  }
  $likes = $json->likes;
  // do something with $likes
} catch (Exception $e) {
  // handle error
}
于 2013-03-19T04:23:14.203 に答える
0

最も簡単な方法は、「php コード」テキスト フィルターを有効にし、ノードを作成して「php 形式」を選択することです。ノード本体に更新された Arlina のコードを配置します。

$graph    = 'https://graph.facebook.com/< your facebook page id>/?fields=likes&access_token=< your application access_token >';
$response = file_get_contents($graph);
$json     = json_decode($response);
try {
if (!isset($json->likes)) {
    throw new Exception('Like count not found in facebook graph object');
}
$likes = $json->likes;
  echo $likes;
} catch (Exception $e) {
// handle error
}

最後にノードを保存します。

于 2015-12-29T22:28:21.763 に答える