1

Ruby で dfa Reporting API (Google API) を使用してレポートを一覧表示しようとしていますが、「ArgumentError: Missing authentication code」というメッセージが表示され続けます。

ここに私が持っているコードがありますが、何か提案はありますか?

require 'google/api_client'
require 'oauth2'

CLIENT_ID = XX
CLIENT_SECRET = XX
REDIRECT_URL = XX
SCOPE = 'https://www.googleapis.com/auth/dfareporting'

refresh_client_obj = OAuth2::Client.new(CLIENT_ID, CLIENT_SECRET, {:site => 'https://accounts.google.com', :authorize_url => '/o/oauth2/auth', :token_url => '/o/oauth2/token'})
refresh_token = OAuth2::AccessToken.new(refresh_client_obj, XX, {refresh_token: XX})
refresh_token.refresh!
puts "Oauth Access Token " + refresh_token.token
puts "Oauth Refresh Token " + refresh_token.refresh_token

client = Google::APIClient.new
client.authorization.client_id = CLIENT_ID
client.authorization.client_secret = CLIENT_SECRET
client.authorization.redirect_uri = REDIRECT_URL
client.authorization.scope = SCOPE
client.authorization.access_token = refresh_token.token
redirect_uri = client.authorization.authorization_uri
dfa = client.discovered_api('dfareporting')

result = client.execute(
  :api_method => dfa.reports.list,
  :parameters =>
    {'profileId' => 'XX'
    }
)
4

0 に答える 0