Google Plus Count url
Asked Answered
T

2

1

I'm trying to get the count of plus one's I have for google plus, I am checking to see if I have the count right with this

https://plusone.google.com/u/0/_/%2B1/fastbutton?count=true&url=MY_URL

I see that google plus rejects my URL (doesn't return 0 or anything)

I wanted to know if anyone can tell me if I have anything wrong in my url, I have these symbols in my url outside of letters and numbers

:
/
.
?
=
&
_

and my url is formatted like this

(protocol)://(server [such as www]).(domain)/(text).php?(text)=(text)&(text)=(digits)&(text)=(text)
Tampon answered 20/8, 2012 at 19:5 Comment(2)
i guess, you can try "escaping" the URL character so that things such as / are passed correctly to the google server...Blowbyblow
check this out: #7404053Blowbyblow
S
1

Use the URL

https://plusone.google.com/_/+1/fastbutton?url=http%3A%2F%2Fwww.yoursite.com%2Fpath%2Fyour%2fcontent

instead and follow the solution found in this question (parse for window.__SSR = {c:)

Strike answered 21/8, 2012 at 8:22 Comment(4)
still won't work for me (see the format of my url, maybe something in there would cause a problem)Tampon
I think I solved it, so how do you make a regex that does that (not comfortable enough with that) I'm able to load the url as a string now, but don't know how to extract the number, also to fix my problem I had to change & symbols to %26 and I sent GPlus_someotherstuff which google changes to googlePlus_someotherstuff so I need to use googlePlus_someotherstuff in my request to google plusTampon
im using php, (I could possibly use javascript instead)Tampon
right, make sure to url_encode the url you wish to examine number of plusones on. In php simply do urlencode($url). A suitable regexp would be preg_match('/window\.__SSR = {c: ([0-9]+)\.0/', $googleplusresonse, $matches); which would result in $matches[1] holding the number of plusones.Strike
L
0

I think you're looking for this. It's ugly and Google clearly doesn't support it, but it still works.

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;
}
Lip answered 16/3, 2013 at 12:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.