• I want to ad the count of facebook page likes in my custom widget , so I have added the following function
    `function new_facebook_likes( $page_link ) {
    $face_link = parse_url( $page_link );

    if ( $face_link[ ‘host’ ] == ‘www.facebook.com’ || $face_link[ ‘host’ ] == ‘facebook.com’ ) {
    $fans = get_transient( ‘fans_count’ );
    if ( empty( $fans ) ) {
    try {
    $data = json_decode( $this->leap_remote_get( ‘https://graph.facebook.com/fql?q=select%20%20like_count%20from%20link_stat%20where%20url=%22’ . $page_link . ‘%22’), true );

    $fans = $data[‘data’][0][‘like_count’];

    } catch ( Exception $e ) {
    $fans = 0;
    }

    if ( !empty( $fans ) ) {
    set_transient( ‘fans_count’, $fans, 1200 );
    if ( get_option( ‘fans_count’ ) != $fans )
    update_option( ‘fans_count’, $fans );
    }

    if ( $fans == 0 && get_option( ‘fans_count’ ) )
    $fans = get_option( ‘fans_count’ );

    elseif ( $fans == 0 && !get_option( ‘fans_count’ ) )
    $fans = 0;
    }
    return $fans;
    }
    }
    but it gives me the following error
    Notice: Undefined index: data in the following line
    $fans = $data[‘data’][0][‘like_count’];

    please advice how I can add the counter of facebook page

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi,

    You’re not getting any data from Facebook FQL, as it is deprecated in the current version of Graph API. Although, there’s another method which you can use: https://developers.facebook.com/docs/graph-api/reference/v2.9/object/likes
    there’s an example for PHP SDK on that page which you can use. Please let me know if you have questions about it.

    Thanks,
    Pavel

    Thread Starter nerminphelopis

    (@nerminphelopis)

    Hii

    Thanks for your response, do you mean to change this line
    json_decode( $this->leap_remote_get( ‘https://graph.facebook.com/fql?q=select%20%20like_count%20from%20link_stat%20where%20url=%22’ . $page_link . ‘%22’), true );

    with another? or how I get the number of likes

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘facebook count page likes’ is closed to new replies.