我试图简单地向谷歌的托管模型 sample.sentiment 发送一个请求。我无法弄清楚如何通过谷歌使用 Oauth 2.0 进行授权,而且我得到了无数个小时。如果你能提供给我这个代码会很有帮助。这就是我的工作。
client = Google::APIClient.new({:application_name => "CCE",:application_version => "1.0"} )
plus = client.discovered_api('prediction')
# Initialize OAuth 2.0 client
client.authorization.client_id = 'my client id'
client.authorization.client_secret = 'my client secret'
client.authorization.redirect_uri = 'my callback url'
client.authorization.scope = 'https://www.googleapis.com/auth/prediction'
# Request authorization
redirect_uri = client.authorization.authorization_uri
# Wait for authorization code then exchange for token
client.authorization.code = '....'
client.authorization.fetch_access_token!
# Make an API call
result = client.execute(
:api_method => plus.activities.list,
:parameters => {'hostedModelName' => 'sample.sentiment', 'userId' => ''})
`