Skip to content

Instantly share code, notes, and snippets.



Last active Feb 12, 2016
What would you like to do?
How to write to the Google Plus moments.insert API endpoint from Ruby.
# This Sinatra endpoint is something I added to the Google Ruby quick-start
# web app -
# It demonstrates how to write to the moments.insert API, for which I
# couldn't find any Ruby examples.
post '/write_activity' do
# Check for stored credentials in the current user's session.
if !session[:token]
halt 401, 'User not connected.'
# Authorize the client and construct a Google+ service.
plus = $client.discovered_api('plus', 'v1')
moment = {
:type => '',
:target => { :id =>,
:description => "description doesn't seem to show up",
:name => 'An example of an AddActivity w/o URL',
:image => '' },
# post a moment/activity to the vault/profile
req_opts = { :api_method => plus.moments.insert,
:parameters => { :collection => 'vault', :userId => 'me', },
:body_object => moment,
response = $client.execute(req_opts).body
# I didn't bother with AJAX for this proof-of-concept:

This comment has been minimized.

Copy link

@alisnic alisnic commented Mar 19, 2015

thank you!


This comment has been minimized.

Copy link

@zauzaj zauzaj commented Feb 12, 2016

I'm working on posting activity to user stream on Google Plus via RoR and I tried to use your solution but always getting this error:

undefined method 'moments' for Google::APIClient::API:0x3fc05fc78594 ID:plus:v1

Do you know how I can solve it or maybe something is changed cuz I see it's not active anymore ?


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment