Skip to content

Instantly share code, notes, and snippets.

@jacquescrocker
Forked from mattetti/gist:1318670
Created October 27, 2011 04:35
Show Gist options
  • Save jacquescrocker/1318784 to your computer and use it in GitHub Desktop.
Save jacquescrocker/1318784 to your computer and use it in GitHub Desktop.
google cloud print pointers
# this works with oauth 0.5.1
client = OAuth2::Client.new(CLIENT_ID, CLIENT_SECRET,
:authorize_url => "/o/oauth2/auth",
:token_url => "/o/oauth2/token",
:site => 'https://accounts.google.com/')
redirect_uri = "#{SERVER_URL}/oauth2callback"
get '/auth' do
url = client.auth_code.authorize_url(
:redirect_uri => redirect_uri,
:scope => 'https://www.googleapis.com/auth/cloudprint',
:response_type => "code",
)
redirect url
end
get '/oauth2callback' do
access_token = client.auth_code.get_token(params[:code], :redirect_uri => redirect_uri)
# use curl to make a request
puts `curl -v -H "X-CloudPrint-Proxy: api-prober" -H "Authorization: GoogleLogin auth=#{access_token.token}" https://www.google.com/cloudprint/search`
# use access token helper to make a request
puts access_token.get("https://www.google.com/cloudprint/search")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment