Ruby on rails 如何在不与用户和浏览器交互的情况下获取Adwords API令牌
我的问题是:如何在不需要与浏览器交互的情况下,仅通过代码获取标记Adwords 现在我运行以下代码:Ruby on rails 如何在不与用户和浏览器交互的情况下获取Adwords API令牌,ruby-on-rails,ruby,google-ads-api,Ruby On Rails,Ruby,Google Ads Api,我的问题是:如何在不需要与浏览器交互的情况下,仅通过代码获取标记Adwords 现在我运行以下代码: token = adwords.authorize () do | auth_url | puts "Hit Auth error, please navigate to URL: \ n \ t% s"% auth_url print 'log in and type the verification code:' VERIFICATION_CODE = gets.chomp
token = adwords.authorize () do | auth_url |
puts "Hit Auth error, please navigate to URL: \ n \ t% s"% auth_url
print 'log in and type the verification code:'
VERIFICATION_CODE = gets.chomp
VERIFICATION_CODE
end
并重叠浏览器url中返回的令牌以释放访问权限
是否只使用Ruby代码来完成所有这些
谢谢。为了离线访问用户的AdWords数据
&access_type=offline
下面是一个完整URL的示例,该URL请求对用户的AdWords数据的脱机权限:
https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=auto&client_id=YOUR_CLIENT_ID&redirect_uri=YOUR_CALLBACK_URL&response_type=code&scope=https%3A%2F%2Fadwords.google.com%2Fapi%2Fadwords%2F
您的客户端ID如下:111122223333.apps.googleusercontent.com
在替换回叫URL之前,请确保正确转义回叫URL
使用刷新令牌
这样,当您获得帐户的access\u令牌
时,您也将在相同的响应中从Google获得refresh\u令牌
。将其与帐户的其余数据(包括access\u令牌
)一起存储在数据库中
稍后,当原始访问令牌过期时,您可以通过以下请求请求新的访问令牌:
https://accounts.google.com/o/oauth2/token?refresh_token=THE_REFRESH_TOKEN&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&grant_type=refresh_token
伟大的非常好,谢谢!