Skip to content

Instantly share code, notes, and snippets.

Created September 21, 2011 23:21
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Google+ to Twitter
#!/usr/bin/env ruby
require 'open-uri'
require 'time'
require 'tmpdir'
require 'rubygems'
require 'oauth'
require 'json/pure'
user_id = '(Your Google+ user ID)'
api_key = '(Your Google API key)'
consumer_key = '(Your OAuth consumer key)'
consumer_secret = '(Your OAuth consumer secret)'
consumer = consumer_key, consumer_secret, :site => "")
access_token = '(Your OAuth access token)'
access_token_secret = '(Your OAuth access token secret)'
token = consumer, access_token, access_token_secret )
tmpfile = Dir.tmpdir+'/gplus2twitter'
obj = open( "{user_id}/activities/public?key=#{api_key}" ){|f| JSON.parse( )} rescue nil
exit unless obj
if File.exist?( tmpfile ) then
prev = open( tmpfile ){|f| Time.parse( )}
prev = - 600 # 10 minutes if first time
r = []
obj['items'].each do |item|
title = item['title']
url = item['url']
date = Time.parse( item['published'] )
if date > prev then
r << ["#{title} #{url}", date]
r.sort_by{|i| i.last}.each do |item, date|
res = '', 'status' => item )
break if res.code != '200'
open( tmpfile, "w" ){|f| f.print date.to_s}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment