草庐IT

android - 获取订阅 token 的 Google Android 订阅 API 过期时间。

coder 2023-11-21 原文

当我发出以下请求时,Google 只给出错误 503,并不会提供任何有用的信息。

我正在关注这里的文档:https://developers.google.com/android-publisher/v1/purchases/get

最近(自动)刷新了授权 token 。 (通常它会在陈旧时显示 401。)

[root@308321 cgi-bin]# wget -dSO- 'https://www.googleapis.com/androidpublisher/v1/applications/com.kizbit.pairfinder/subscriptions/subscription99/purchases/vkorjajxnjfyhxbftpymwfox?access_token=ya29.AHES6ZSnxLdOVf2QWrX96VbpDMdUKlHFXJOFEdHM_f_ErQlL'
Setting --server-response (serverresponse) to 1
Setting --output-document (outputdocument) to -
DEBUG output created by Wget 1.12 on linux-gnu.

--2012-07-05 00:09:46--  https://www.googleapis.com/androidpublisher/v1/applications/com.kizbit.pairfinder/subscriptions/subscription99/purchases/vkorjajxnjfyhxbftpymwfox?access_token=ya29.AHES6ZSnxLdOVf2QWrX96VbpDMdUKlHFXJOFEdHM_f_ErQlL
Resolving www.googleapis.com... 2001:4860:b007::5f, 74.125.142.95
Caching www.googleapis.com => 2001:4860:b007::5f 74.125.142.95
Connecting to www.googleapis.com|2001:4860:b007::5f|:443... connected.
Created socket 3.
Releasing 0x0000000000cc9370 (new refcount 1).
Initiating SSL handshake.
Handshake successful; connected socket 3 to SSL handle 0x0000000000cd8e70
certificate:
  subject: /C=US/ST=California/L=Mountain View/O=Google Inc/CN=*.googleapis.com
  issuer:  /C=US/O=Google Inc/CN=Google Internet Authority
X509 certificate successfully verified and matches host www.googleapis.com

---request begin---
GET /androidpublisher/v1/applications/com.kizbit.pairfinder/subscriptions/subscription99/purchases/vkorjajxnjfyhxbftpymwfox?access_token=ya29.AHES6ZSnxLdOVf2QWrX96VbpDMdUKlHFXJOFEdHM_f_ErQlL HTTP/1.0
User-Agent: Wget/1.12 (linux-gnu)
Accept: */*
Host: www.googleapis.com
Connection: Keep-Alive

---request end---
HTTP request sent, awaiting response...
---response begin---
HTTP/1.0 503 Service Unavailable
Content-Type: application/json; charset=UTF-8
Date: Thu, 05 Jul 2012 04:09:56 GMT
Expires: Thu, 05 Jul 2012 04:09:56 GMT
Cache-Control: private, max-age=0
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE

---response end---

  HTTP/1.0 503 Service Unavailable
  Content-Type: application/json; charset=UTF-8
  Date: Thu, 05 Jul 2012 04:09:56 GMT
  Expires: Thu, 05 Jul 2012 04:09:56 GMT
  Cache-Control: private, max-age=0
  X-Content-Type-Options: nosniff
  X-Frame-Options: SAMEORIGIN
  X-XSS-Protection: 1; mode=block
  Server: GSE
Closed 3/SSL 0x0000000000cd8e70
2012-07-05 00:09:47 ERROR 503: Service Unavailable.

最佳答案

@imrankhan。以下是在 Perl 中的操作方法:

sub refreshAccessToken {
    my $ua = LWP::UserAgent->new;
    my $req = HTTP::Request->new(POST => 'https://accounts.google.com/o/oauth2/token');
    $req->content_type('application/x-www-form-urlencoded');
    $req->content('grant_type=refresh_token&client_id=9999999.apps.googleusercontent.com&client_secret=xxxxxxxxxxxxxxxx&refresh_token='.$REFRESH_TOKEN);
    # grant_type=refresh_token
    # client_id=<the client ID token created in the APIs Console>
    # client_secret=<the client secret corresponding to the client ID>
    # refresh_token=<the refresh token from the very first authorization step>
    my $res = $ua->request($req);
    if ($res->is_success()) { # parse JSON
        #print $res->content . "\n";
        # {
          # "access_token" : "ya29.AHES3ZQ_MxxxxTeSl530Na2",
          # "token_type" : "Bearer",
          # "expires_in" : 3600,
        # }
        my $json = decode_json($res->content);
        my $accessToken = $json->{'access_token'};
        saveAccessToken($accessToken);
    } else {
        serverError($ERROR_GOOGLE, 'Could not refresh subscription access token from Google server. '.$res->status_line);
        exit;
    }
}

关于android - 获取订阅 token 的 Google Android 订阅 API 过期时间。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11337799/

有关android - 获取订阅 token 的 Google Android 订阅 API 过期时间。的更多相关文章

  1. ruby-on-rails - Rails 中的 NoMethodError::MailersController#preview undefined method `activation_token=' for nil:NilClass - 2

    似乎无法为此找到有效的答案。我正在阅读Rails教程的第10章第10.1.2节,但似乎无法使邮件程序预览正常工作。我发现处理错误的所有答案都与教程的不同部分相关,我假设我犯的错误正盯着我的脸。我已经完成并将教程中的代码复制/粘贴到相关文件中,但到目前为止,我还看不出我输入的内容与教程中的内容有什么区别。到目前为止,建议是在函数定义中添加或删除参数user,但这并没有解决问题。触发错误的url是http://localhost:3000/rails/mailers/user_mailer/account_activation.http://localhost:3000/rails/mai

  2. ruby-on-rails - Ruby 检查日期时间是否为 iso8601 并保存 - 2

    我需要检查DateTime是否采用有效的ISO8601格式。喜欢:#iso8601?我检查了ruby​​是否有特定方法,但没有找到。目前我正在使用date.iso8601==date来检查这个。有什么好的方法吗?编辑解释我的环境,并改变问题的范围。因此,我的项目将使用jsapiFullCalendar,这就是我需要iso8601字符串格式的原因。我想知道更好或正确的方法是什么,以正确的格式将日期保存在数据库中,或者让ActiveRecord完成它们的工作并在我需要时间信息时对其进行操作。 最佳答案 我不太明白你的问题。我假设您想检查

  3. ruby - 简单获取法拉第超时 - 2

    有没有办法在这个简单的get方法中添加超时选项?我正在使用法拉第3.3。Faraday.get(url)四处寻找,我只能先发起连接后应用超时选项,然后应用超时选项。或者有什么简单的方法?这就是我现在正在做的:conn=Faraday.newresponse=conn.getdo|req|req.urlurlreq.options.timeout=2#2secondsend 最佳答案 试试这个:conn=Faraday.newdo|conn|conn.options.timeout=20endresponse=conn.get(url

  4. ruby-on-rails - ActionController::RoutingError: 未初始化常量 Api::V1::ApiController - 2

    我有用于控制用户任务的Rails5API项目,我有以下错误,但并非总是针对相同的Controller和路由。ActionController::RoutingError:uninitializedconstantApi::V1::ApiController我向您描述了一些我的项目,以更详细地解释错误。应用结构路线scopemodule:'api'donamespace:v1do#=>Loginroutesscopemodule:'login'domatch'login',to:'sessions#login',as:'login',via::postend#=>Teamroutessc

  5. ruby - 从 Ruby 中的主机名获取 IP 地址 - 2

    我有一个存储主机名的Ruby数组server_names。如果我打印出来,它看起来像这样:["hostname.abc.com","hostname2.abc.com","hostname3.abc.com"]相当标准。我想要做的是获取这些服务器的IP(可能将它们存储在另一个变量中)。看起来IPSocket类可以做到这一点,但我不确定如何使用IPSocket类遍历它。如果它只是尝试像这样打印出IP:server_names.eachdo|name|IPSocket::getaddress(name)pnameend它提示我没有提供服务器名称。这是语法问题还是我没有正确使用类?输出:ge

  6. ruby - 获取模块中定义的所有常量的值 - 2

    我想获取模块中定义的所有常量的值:moduleLettersA='apple'.freezeB='boy'.freezeendconstants给了我常量的名字:Letters.constants(false)#=>[:A,:B]如何获取它们的值的数组,即["apple","boy"]? 最佳答案 为了做到这一点,请使用mapLetters.constants(false).map&Letters.method(:const_get)这将返回["a","b"]第二种方式:Letters.constants(false).map{|c

  7. ruby-on-rails - 将 Ruby 中的日期/时间格式化为 YYYY-MM-DD HH :MM:SS - 2

    这个问题在这里已经有了答案:Railsformattingdate(4个答案)关闭4年前。我想格式化Time.Now函数以显示YYYY-MM-DDHH:MM:SS而不是:“2018-03-0909:47:19+0000”该函数需要放在时间中.现在功能。require‘roo’require‘roo-xls’require‘byebug’file_name=ARGV.first||“Template.xlsx”excel_file=Roo::Spreadsheet.open(“./#{file_name}“,extension::xlsx)xml=Nokogiri::XML::Build

  8. ruby - 查找字符串中的内容类型(数字、日期、时间、字符串等) - 2

    我正在尝试解析一个CSV文件并使用SQL命令自动为其创建一个表。CSV中的第一行给出了列标题。但我需要推断每个列的类型。Ruby中是否有任何函数可以找到每个字段中内容的类型。例如,CSV行:"12012","Test","1233.22","12:21:22","10/10/2009"应该产生像这样的类型['integer','string','float','time','date']谢谢! 最佳答案 require'time'defto_something(str)if(num=Integer(str)rescueFloat(s

  9. ruby-on-rails - 获取 inf-ruby 以使用 ruby​​ 版本管理器 (rvm) - 2

    我安装了ruby​​版本管理器,并将RVM安装的ruby​​实现设置为默认值,这样'哪个ruby'显示'~/.rvm/ruby-1.8.6-p383/bin/ruby'但是当我在emacs中打开inf-ruby缓冲区时,它使用安装在/usr/bin中的ruby​​。有没有办法让emacs像shell一样尊重ruby​​的路径?谢谢! 最佳答案 我创建了一个emacs扩展来将rvm集成到emacs中。如果您有兴趣,可以在这里获取:http://github.com/senny/rvm.el

  10. Ruby 从大范围中获取第 n 个项目 - 2

    假设我有这个范围:("aaaaa".."zzzzz")如何在不事先/每次生成整个项目的情况下从范围中获取第N个项目? 最佳答案 一种快速简便的方法:("aaaaa".."zzzzz").first(42).last#==>"aaabp"如果出于某种原因你不得不一遍又一遍地这样做,或者如果你需要避免为前N个元素构建中间数组,你可以这样写:moduleEnumerabledefskip(n)returnto_enum:skip,nunlessblock_given?each_with_indexdo|item,index|yieldit

随机推荐