Skip to content

Instantly share code, notes, and snippets.

@psylone
Created April 2, 2014 15:48
Show Gist options
  • Save psylone/9936865 to your computer and use it in GitHub Desktop.
Save psylone/9936865 to your computer and use it in GitHub Desktop.
require 'google/api_client' # version 0.7.1
# Set purchase data hash
data = {
token: 'gldfdkfjpnnhmnclekpndgph.AO-J1OwXKIzAKUzprnFnNTClSoe7AYx4kF6_d5IujRI7jiTUIHMwQq0oV_fXyjMXf3sUzpCaS0lUWXvqpraR5Pp5Fmk4MvN7CbGDU0lgAg_kqvKDgT1A9y6C3mpBjYBLPN64plT78M-V',
productId: 'chebucks18',
packageName: 'com.snegoffon.corruption'
}
# Initialize client
client = Google::APIClient.new
# Build method for request
method = client.discovered_api('androidpublisher', 'v1.1').inapppurchases.get
# Load key from Google Developers Console
key = Google::APIClient::KeyUtils.load_from_pkcs12('config/google-api-privatekey.p12', 'notasecret')
# Build authorization object
client.authorization = Signet::OAuth2::Client.new(
:token_credential_uri => 'https://accounts.google.com/o/oauth2/token',
:audience => 'https://accounts.google.com/o/oauth2/token',
:scope => 'https://www.googleapis.com/auth/androidpublisher',
:issuer => '694168420610-sh9dpuvldpeu8obmnujs3l4ari16q5h5@developer.gserviceaccount.com',
:signing_key => key)
# Get access_token
client.authorization.fetch_access_token!
# Until this moment everything is fine: access_token was successfully fetched
# Do the query to Purchase Status API
client.execute(api_method: method, parameters: data)
# => 403
# {
# "error" =>
# {
# "errors" =>
# {
# "domain"=>"global",
# "reason"=>"forbidden",
# "message"=>"Forbidden"
# }
# }
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment