Guest User

Untitled

a guest
Feb 16th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. {
  2. "error": {
  3. "errors": [
  4. {
  5. "domain": "androidpublisher",
  6. "reason": "permissionDenied",
  7. "message": "The current user has insufficient permissions to perform the requested operation."
  8. }
  9. ],
  10. "code": 401,
  11. "message": "The current user has insufficient permissions to perform the requested operation."
  12. }
  13. }
  14.  
  15. scopes = ['https://www.googleapis.com/auth/androidpublisher']
  16. authorization = Google::Auth.get_application_default(scopes)
  17.  
  18. uri = "https://www.googleapis.com/androidpublisher/v3/applications/#{ENV['ANDROID_PACKAGE_NAME']}/purchases/products/#{purchasable.purchase_uuid}/tokens/#{purchase_token}?access_token=#{authorization.fetch_access_token!['access_token']}"
  19.  
  20. response = RestClient::Request.execute method: :get,
  21. url: uri,
  22. headers: {'Content-Type':'application/json'}
  23.  
  24. file = File.read('config/google_key.json')
  25. values = JSON.parse(file)
  26.  
  27.  
  28. oauth = Signet::OAuth2::Client.new(
  29. issuer: values[:client_email]",
  30. audience: "https://www.googleapis.com/oauth2/v4/token",
  31. scope: "https://www.googleapis.com/auth/androidpublisher",
  32. client_id: values[:client_id],
  33. signing_key: OpenSSL::PKey::RSA.new(values[:private_key]),
  34. )
  35.  
  36. jwt = oauth.to_jwt
  37.  
  38. url = "https://www.googleapis.com/oauth2/v4/token"
  39. begin
  40. response = RestClient::Request.execute method: :post,
  41. url: url,
  42. headers: {'Content-Type': 'application/json'},
  43. payload: {
  44. grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
  45. assertion: jwt
  46. }
  47.  
  48. result = JSON.parse response.body
  49. rescue => e
  50. puts e.response.to_str
  51. result = JSON.parse(e.response.to_s)
  52. end
Add Comment
Please, Sign In to add comment