ech*_*ppy 4 ruby android ruby-on-rails in-app-purchase google-play
我一直在谷歌搜索和搜索这是杀了我.我只是想设置我们的RoR服务器,以便能够查询谷歌游戏购买API,以验证订阅是否已更新,我似乎无法找到实际的解决方案.我已经浏览了所有的谷歌文档.看来我需要一个如此处所述的服务帐户
https://developers.google.com/accounts/docs/OAuth2ServiceAccount
但后来我发现这篇关于他们实际上希望我们如何使用Web服务器应用程序流的python文章
http://milancermak.wordpress.com/2012/08/24/server-side-verification-of-google-play-subsc/
我现在并不在意,我只需要让服务器成功地与Google API通信以验证/续订订阅.我找到了0条关于这个流如何工作的文章.有没有人得到这个工作?
对于那些偶然发现这一点的人来说,这是我曾经遇到过的最疯狂的事情,但我设法弄清楚并且做得对.我要感谢以下文章,以帮助我慢慢地,但肯定到底这一点.我将添加最令人惊讶的部分是我将在下面列出的步骤,我不是100%确信它们都是必要的,因为我在此期间遇到的唯一错误是"403 Insufficient Permissions"所以我真的可以做到这里告诉你我所做的一切,并希望它对你有用.
本文使一切正常,但使用Web访问方法并声明服务帐户不起作用
http://milancermak.wordpress.com/2012/08/24/server-side-verification-of-google-play-subsc/
对于上面的Ruby文章,这是一个很好的实现
https://gist.github.com/cornflakesuperstar/5632813
这是一篇关于如何获取密钥的文章,以便您可以将其存储为Heroku的环境变量
http://ar.zu.my/how-to-store-private-key-files-in-heroku/
这是一篇关于如何设置服务帐户的好文章(注意我不是我们服务的帐户所有者,因此我不知道如何做到这一点.这篇文章有效)
https://developers.google.com/console/help/#activatingapis
这篇文章是关于如何从上面授权自动生成的电子邮件的文章
如何使用OAuth 2.0为Ruby中的google预测API进行授权?
API的官方Google实施就在这里
https://developers.google.com/android-publisher/api-ref/purchases/subscriptions/get
自从我发布这篇文章以来无数个深夜之后,我能够通过以下步骤使用服务帐户
经过大量的试验和错误,奇迹般地从API获得了"200".这是我的代码
ISSUER = '45366745684568-afdasfasdfasdfasdfasdf@developer.gserviceaccount.com' # From service account
APP_NAME = '<appname>' # This value didn't seem to matter. I think it is for logging
APP_VERSION = '1.0' # This value didn't seem to matter. I think it is for logging
class SomeClass < ActiveRecord::Base
def self.google_api_client
@@google_client ||= Google::APIClient.new(
application_name: APP_NAME,
application_version: APP_VERSION
).tap do |client|
# Load the key downloaded from the Google Developer Console
if ENV['GOOGLE_API_KEY'].nil?
puts "Be sure that you have ENV['GOOGLE_API_KEY'] defined in your environment."
return
end
key = OpenSSL::PKey::RSA.new ENV['GOOGLE_API_KEY'], 'notasecret'
# Initialize the connection
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 => ISSUER,
:signing_key => key)
client.authorization.fetch_access_token!
end
end
def self.test_server(package_name, subscription_id, token)
# Get the client
client = self.google_api_client
# Discover the subscriptions API
publisher = client.discovered_api('androidpublisher', 'v2')
# Make the API call
result = client.execute(
:api_method => publisher.purchases.subscriptions.get,
:parameters => {'packageName' => package_name, 'subscriptionId' => subscription_id, 'token' => token}
)
end
end
Run Code Online (Sandbox Code Playgroud)
一旦我完成了上述所有步骤,我仍然在努力(同样的403错误).我意识到燃烧我的是'范围'未正确设置为' https://www.googleapis.com/auth/androidpublisher '.我希望这真的能帮助别人.这让我分崩离析,现在它完美无缺.
感谢所有上述文章的帮助.
| 归档时间: |
|
| 查看次数: |
1848 次 |
| 最近记录: |