Last active
November 5, 2015 16:28
-
-
Save jice-lavocat/0e90de5b8b59737643c1 to your computer and use it in GitHub Desktop.
Import Gplus shares - Based on http://blog.elokenz.com/content-marketing/google-shares-retrieve
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$target="http://www.wordiz.it"; | |
$data="f.req=%5B%22".$target."%22%2Cnull%5D&"; | |
$url = "https://plus.google.com/u/0/ripple/update"; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array('application/x-www-form-urlencoded')); | |
$curl_results = curl_exec ($ch); | |
curl_close ($ch); | |
//echo $curl_results; | |
$curl_results=substr($curl_results,6); | |
$curl_results = str_replace(",,",",null,", $curl_results); | |
$curl_results = str_replace(",,",",null,", $curl_results); | |
// print_r($curl_results); | |
$parsed_results = json_decode($curl_results, true); | |
echo($parsed_results[0][1][4])." Google shares on ".$target; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib,urllib2,json | |
target_url="http://www.wordiz.it" | |
target=urllib.quote_plus(target_url+"#__sid=0") #url-friendly | |
data = 'f.req=%5B%22'+target+'%22%2Cnull%5D&' | |
url = "https://plus.google.com/u/0/ripple/update" | |
req = urllib2.Request(url, data, {'Content-Type': 'application/x-www-form-urlencoded'}) | |
f = urllib2.urlopen(req) | |
response = f.read() | |
f.close() | |
response=response[6:] #remove some bad characters | |
# Remove ",," (non valid json) and replace with ,null, ( | |
# Do that twice because re do not take into account overlapping matches) | |
response_json_str = response.replace(",,", ",null,").replace(",,", ",null,") | |
datas = json.loads(response_json_str) | |
# Find relevant data -- might need to be changed depending on possible incoming format | |
# Maybe need some recursive func searching for list with first item "orr.c" | |
orr_c = datas[0][1][-3] | |
print str(orr_c)+" share(s) pour "+target_url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment