我正在尝试通过将此数据调整到rails https://github.com/google/google-api-ruby-client来显示来自Google+的数据。我创建了一个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(我认为)这是一个公共电话?注意:我更改了此帖子以回应显示我当前工作状态的建议。
答案 0 :(得分:0)
尝试用 $authorization.execute
plus.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'}
)