将Google+集成到Rails应用程序中(执行不起作用)



我正试图通过将其调整为rails来显示Google+中的数据https://github.com/google/google-api-ruby-client我创建了一个rails应用程序,做了一些调整以使oauth与client_secret.json一起工作,但当请求执行时,什么都不显示。

welcome_controller:

class WelcomeController < ApplicationController
def index
require 'google/api_client'
require 'google/api_client/client_secrets'
require 'google/api_client/auth/installed_app'
$credentials = Google::APIClient::ClientSecrets.load
# Initialize the client.
$authorization = Signet::OAuth2::Client.new(
:authorization_uri => $credentials.authorization_uri,
:token_credential_uri => $credentials.token_credential_uri,
:client_id => $credentials.client_id,
:client_secret => $credentials.client_secret,
:redirect_uri => $credentials.redirect_uris.first,
:scope => 'https://www.googleapis.com/auth/plus.login')
@client = Google::APIClient.new(
:application_name => 'X',
:application_version => 'X'
)
# Initialize Google+ API. Note this will make a request to the
# discovery service every time, so be sure to use serialization
# in your production code. Check the samples for more details.
@plus = @client.discovered_api( "plus", "v1" )
# Make an API call.
@google_plus_info = @client.execute(
:api_method => @plus.activities.list,
:parameters => {'collection' => 'public', 'userId' => 'my_num_here'}
)
#puts @google_plus_info.data  #tried this
render plain: "test: #{@google_plus_info.data}" #tried this too, just returns the call name
end
end

有人知道为什么我在这种情况下得到它,根据API(我认为)这是一个公开呼吁?注意:我更改了这篇帖子,以回应建议,显示我目前的工作状态。

尝试用plus.execute替换$authorization.execute

看看https://github.com/google/google-api-ruby-client-samples/tree/master/googleplus

以下是我的工作代码片段:

@client = Google::APIClient.new(
  :application_name => 'X',
  :application_version => 'X'
)
@client.authorization.update_token!(:access_token => 'X', :refresh_token => 'X')
@plus = @client.discovered_api( "plus", "v1" )
@google_plus_info = @client.execute(
  :api_method => @plus.people.get,
  :parameters => {'collection' => 'public', 'userId' => 'me'}
)

最新更新