Access the Google+ API (Ruby) in public mode

I want to make an equivalent, for example. this API browser call using google ruby ​​API .

It should be simple:

require 'rubygems'
require 'google/api_client'
require 'httpadapter/adapters/net_http'

@client = Google::APIClient.new(
  :key => MY_SIMPLE_API_SERVER_KEY,
  :host => 'www.googleapis.com',
  :http_adapter => HTTPAdapter::NetHTTPAdapter.new, 
  :pretty_print => false
)
@plus = @client.discovered_api('plus', 'v1')

status, headers, body = @client.execute(
  @plus.people.list_by_activity,
  'activityId' => 'z12nspyxxufislit423eex442zqpdtqnk',
  'collection' => 'plusoners',
  'maxResults' => '100',
  'authenticated' => 'false'
)
public_activity = JSON.parse(body[0])

However, the call executecausesArgumentError: Missing access token.

I do not want to register users; I want to access public data. How to do it?

+5
source share
2 answers

I poked into the client code and found a couple of options.

-, API, . , , , . , . :

require 'rubygems'
require 'google/api_client'
require 'httpadapter/adapters/net_http'

@client = Google::APIClient.new(
  :key => 'SOME_KEY',
  :host => 'www.googleapis.com',
  :http_adapter => HTTPAdapter::NetHTTPAdapter.new, 
  :pretty_print => false
)
@client.authorization = nil

@plus = @client.discovered_api('plus', 'v1')

status, headers, body = @client.execute(
  @plus.people.list_by_activity,
  'activityId' => 'z12nspyxxufislit423eex442zqpdtqnk',
  'collection' => 'plusoners',
  'maxResults' => '100'
)
public_activity = JSON.parse(body[0])

. ! , :

require 'rubygems'
require 'google/api_client'
require 'httpadapter/adapters/net_http'

@client = Google::APIClient.new(
  :key => 'SOME_KEY',
  :host => 'www.googleapis.com',
  :http_adapter => HTTPAdapter::NetHTTPAdapter.new, 
  :pretty_print => false
)
@plus = @client.discovered_api('plus', 'v1')

status, headers, body = @client.execute(
  @plus.people.list_by_activity,
  {'activityId' => 'z12nspyxxufislit423eex442zqpdtqnk',
  'collection' => 'plusoners',
  'maxResults' => '100'}, '', [], {:authenticated => false}
)
puts status
puts body
public_activity = JSON.parse(body[0])

Allen, Google+:)

+3
0

All Articles