Difficulty getting google plus one count

前端 未结 2 412
南方客
南方客 2021-01-14 22:24

I have been searching all over the internet on how to get programaticaly google plus one button count. Finally i found this article Here is the Php Script mentioned in the

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-14 23:08

    The cURL and API way listed in the other posts here no longer works.

    There is still at least 1 method, but it's ugly and Google clearly doesn't support it. You just rip the variable out of the JavaScript source code for the official button with a regular expression:

    function shinra_gplus_get_count( $url ) {
        $contents = file_get_contents( 
            'https://plusone.google.com/_/+1/fastbutton?url=' 
            . urlencode( $url ) 
        );
    
        preg_match( '/window\.__SSR = {c: ([\d]+)/', $contents, $matches );
    
        if( isset( $matches[0] ) ) 
            return (int) str_replace( 'window.__SSR = {c: ', '', $matches[0] );
        return 0;
    }
    

提交回复
热议问题