facebook count page likes
-
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
- The topic ‘facebook count page likes’ is closed to new replies.