-2

ここにこのコードがあります。ここで、$friends変数は次のような出力を持つ配列です。

{
  "id": "1149862205",
  "name": "name",
  "first_name": "first_name",
  "last_name": "last_name",
  "link": "https://www.facebook.com/username",
  "username": "username",
  "birthday": "07/12/1990",
  "hometown": {
    "id": "108618265828550",
    "name": "name"
  }, 

$fbfriendlikes変数はのIDによって生成され、次の構造を持ってい$friendsます:

{
  "data": [
    {
      "name": "Penelope-ns-test",
      "category": "Community",
      "id": "187099821418102",
      "created_time": "2012-06-14T15:00:59+0000"
    },

$friendsここで、コード内の特定の ID のようなすべての ID を出力する必要があります。$fbfriendlikes コードは次のようになります。

$friends = $facebook->api('/me/friends');
if (!empty($friends['data'])) {
    $size = variable_get('facebook_graph_pic_size_nodes','square');
    $protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https' : 'http';
    foreach ($friends['data'] as $data) {
        $fbid = $data['id'];
        $fbfriendlikes[$fbid]=$facebook->api('/'.$fbid.'/likes'); 
        $fbname = $data['name'];
        $path = $protocol . '://graph.facebook.com/' . $fbid . '/picture?type=' . $size;
        $image = theme('image', array('path' => $path, 'alt' => $fbname));

        if ($fbfriendlikes["id"] != 184759054887922) {
            $return .= '<div class="fimage">'.$image.'</div>';
            $link = '<a href="'.$protocol . '://www.facebook.com/profile.php?id='.$fbid.'" target="_blank">'.$fbname.'</a>';    
            $return .= '<div class="flink">'.$link.'</div>';
            break;
        }
    }
}

foreach ループを実行する必要があることは$fbfriendslikesわかっていますが、それを機能させることができないようです。アドバイスをお願いできますか?

4

2 に答える 2

0

気に入らないものを取得するには、ループ内をチェックする必要があります。

$return = '';
$friends = $facebook->api('/me/friends');
if (!empty($friends['data'])) {
    $size = variable_get('facebook_graph_pic_size_nodes','square');
    $protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https' : 'http';
    foreach ($friends['data'] as $data) {
        $fbid = $data['id'];
        $fbfriendlikes[$fbid]=$facebook->api('/'.$fbid.'/likes'); 
        $fbname = $data['name'];
        $path = $protocol . '://graph.facebook.com/' . $fbid . '/picture?type=' . $size;
        $image = theme('image', array('path' => $path, 'alt' => $fbname));

        foreach($fbfriendlikes['data'] as $like) {
            $likes = false; // set var to check for like
            if($like['id'] == '184759054887922') { // check if they liked it
                $likes = true; // set var to true because they liked it
            }
            if (!$likes) { // test var to see if false (they did not like)
                // print this if they did NOT like it, otherwise do nothing
                $return .= '<div class="fimage">'.$image.'</div>';
                $link = '<a href="'.$protocol . '://www.facebook.com/profile.php?id='.$fbid.'" target="_blank">'.$fbname.'</a>';    
                $return .= '<div class="flink">'.$link.'</div>';
            }
        }// go on to next in loop

    }
    echo $return;
}
于 2012-06-26T12:37:50.487 に答える
0

これを試して:

$return = '';
$friends = $facebook->api('/me/friends');
if (!empty($friends['data'])) {
    $size = variable_get('facebook_graph_pic_size_nodes','square');
    $protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https' : 'http';
    foreach ($friends['data'] as $data) {
        $fbid = $data['id'];
        $fbfriendlikes[$fbid]=$facebook->api('/'.$fbid.'/likes'); 
        $fbname = $data['name'];
        $path = $protocol . '://graph.facebook.com/' . $fbid . '/picture?type=' . $size;
        $image = theme('image', array('path' => $path, 'alt' => $fbname));

        $likes = false;
        foreach($fbfriendlikes['data'] as $like) {
            if($like['id'] == '184759054887922') { // maybe $like->id will have to be used instead...
                $likes = true;
                break;
            }
        }

        if (!$likes) {
            $return .= '<div class="fimage">'.$image.'</div>';
            $link = '<a href="'.$protocol . '://www.facebook.com/profile.php?id='.$fbid.'" target="_blank">'.$fbname.'</a>';    
            $return .= '<div class="flink">'.$link.'</div>';
        }
    }
    echo $return;
}
于 2012-06-26T08:45:09.793 に答える