Hi,
So, we're having some issues with authentication in Ruby.
In our application, the user logs in and grants offline access. This seems to be working ok, we're getting both the access and refresh token and we're stashing them in the database as a hash that reads
{access_token => 'XYZ',
refresh_token => 'ABC'}
We then have a backend process that is supposed to go through each job for that day and make the alterations the user wants using their stored credentials. This is where that task is falling down. Code at present is;
require 'adwords_api'
class Job
def initialize(job)
def initialize(job)
@uniqueid = job.uniqueid
@campaignid = job.campaignid
@adgroupid = job.adgroupid
@authtoken = eval(job.token)
end
def get_report(report_type)
adwords = AdwordsApi::Api.new
jobtoken = @authtoken
token = adwords.authorize({
:oauth2_token => jobtoken
})
api_version = :v201603
report_def_srv = adwords.service(:ReportDefinitionService, api_version)
fields = report_def_srv.get_report_fields(report)
end
(yeah, I know the eval on the jobtoken isn't secure) This works fine, and when I call get_report I get the data back.....so long as it's reasonably soon after the user granted authentication and the access token is still valid. Once that's no longer true, I get
AdwordsApi::V201603::ReportDefinitionService::ApiException: [AuthenticationError.OAUTH_TOKEN_INVALID @ ; trigger:'<null>']
I know there's supposed to be some sort of handshake where I give Google the refresh token and in exchange get the new access token, but the docs seem to suggest the Adwords Gem should handle that itself?
If anyone's got any ideas they'd be much appreciated.