Last active
April 23, 2016 16:07
-
-
Save TheBojda/d7354b7a72f2bf275e6d206988b51f52 to your computer and use it in GitHub Desktop.
Generate RSS feed from Google Plus public feed for using it as IFTTT source, or whatever ...
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 | |
function getSslPage($url) { | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); | |
curl_setopt($ch, CURLOPT_HEADER, false); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_REFERER, $url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | |
$result = curl_exec($ch); | |
curl_close($ch); | |
return $result; | |
} | |
function startsWith($haystack, $needle) { | |
return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== false; | |
} | |
$api_key = '.. api key ..'; | |
$user_id = '.. user id ..'; | |
$activity_feed = json_decode(getSslPage("https://www.googleapis.com/plus/v1/people/$user_id/activities/public?fields=items(object(attachments(content%2CdisplayName%2Curl)%2Ccontent)%2Cpublished%2Curl)%2Ctitle%2Cupdated&key=$api_key")); | |
header('Content-Type: text/xml;charset=UTF-8'); | |
?> | |
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0"> | |
<channel> | |
<title>Google+ Feed</title> | |
<description>Laszlo Fazekas G+ feed</description> | |
<link>https://plus.google.com/+LaszloFazekas/posts</link> | |
<?php foreach($activity_feed->items as $item): ?> | |
<item> | |
<?php if(startsWith($item->object->content, '<a ')): // link only ?> | |
<title><![CDATA[<?php | |
if(isset($item->object->attachments)) | |
echo $item->object->attachments[0]->displayName; | |
?>]]></title> | |
<link><?php echo $item->url; ?></link> | |
<guid><?php echo $item->url; ?></guid> | |
<description><![CDATA[<?php | |
if(isset($item->object->attachments)) { | |
if($item->object->attachments[0]->content) | |
echo $item->object->attachments[0]->content; | |
else | |
echo $item->object->content; | |
} | |
?>]]></description> | |
<?php else: ?> | |
<title></title> | |
<link><?php echo $item->url; ?></link> | |
<guid><?php echo $item->url; ?></guid> | |
<description><![CDATA[<?php | |
echo $item->object->content; | |
?>]]></description> | |
<?php endif; ?> | |
<pubDate><?php echo gmdate(DATE_RFC822, strtotime($item->published)); ?></pubDate> | |
</item><?php endforeach; ?> | |
</channel> | |
</rss> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment