Skip to content

Instantly share code, notes, and snippets.

@janithl
Last active November 18, 2021 07:54
Show Gist options
  • Save janithl/1513183 to your computer and use it in GitHub Desktop.
Save janithl/1513183 to your computer and use it in GitHub Desktop.
PHP script for turning your Google+ feeds into valid RSS. You need to edit a couple of places but I'm sure you're smart enough to figure that out... :)
<?php
header('Content-type: text/xml');
$gendate = date('r', time());
$config = array(
'gplusid' => '116783522121096138585',
'gplusname' => 'Janith Leanage',
'hosturl' => 'http://janith.vacau.com/gplus'
);
$data = file_get_contents("https://plus.google.com/_/stream/getactivities/?&sp=[1,2,$config['gplusid'],null,null,10,null,\"social.google.com\",[]]");
//remove first shits
$parsed = str_replace(")]}'", "", $data);
//convert
$parsed = str_replace('[,' , '["",' , $parsed);
$parsed = str_replace(',,' , ',"",' , $parsed);
$parsed = str_replace(',,' , ',"",' , $parsed);
$parsed_data = json_decode($parsed);
$stream = $parsed_data[0][1][0];
echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
>
<channel>
<title><?= $config['gplusname'] ?> on Google+</title>
<atom:link href="<?= $config['hosturl'] ?>" rel="self" type="application/rss+xml" />
<link>https://plus.google.com/<?= $config['gplusid'] ?>/posts</link>
<description><?= $config['gplusname'] ?> has a Google+ account, and he's making an RSS feed of his postings there</description>
<lastBuildDate><?= $gendate ?></lastBuildDate>
<language>en</language>
<sy:updatePeriod>hourly</sy:updatePeriod>
<sy:updateFrequency>1</sy:updateFrequency>
<generator><?= $config['gplusname'] ?>'s G+ RSS generator</generator>
<?php for($a = 0; $a < 10; $a++): ?>
<item>
<title><?= $stream[$a][4] ?></title>
<link><?= $stream[$a][21] ?></link>
<comments><?= $stream[$a][21] ?>#comments</comments>
<pubDate><?= date('r', (int)($stream[$a][5] / 1000) ?></pubDate>
<dc:creator><?= $config['gplusname'] ?></dc:creator>
<description><![CDATA[<?= isset($stream[$a][11][0][3]) ? $stream[$a][11][0][3] : '' ?>]]></description>
</item>
<?php endfor; ?>
</channel>
</rss>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment