Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何在不与用户和浏览器交互的情况下获取Adwords API令牌_Ruby On Rails_Ruby_Google Ads Api - Fatal编程技术网

Ruby on rails 如何在不与用户和浏览器交互的情况下获取Adwords API令牌

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

我的问题是:如何在不需要与浏览器交互的情况下,仅通过代码获取标记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 
  VERIFICATION_CODE 
end 
并重叠浏览器url中返回的令牌以释放访问权限

是否只使用Ruby代码来完成所有这些


谢谢。

为了离线访问用户的AdWords数据

  • 他们必须授予你的应用程序脱机权限
  • 您必须存储并使用刷新令牌,以便在初始令牌过期后获得新的访问令牌
  • 请求脱机权限 要请求脱机权限,只需将以下查询参数添加到OAuth2 URL:

    &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
    

    伟大的非常好,谢谢!