2012-07-05 37 views
10

Khi tôi thực hiện yêu cầu sau, Google chỉ cung cấp lỗi 503 và sẽ không cung cấp bất kỳ thông tin hữu ích nào.Nhận thời gian hết hạn API đăng ký Google Android cho mã thông báo đăng ký.

Tôi đang theo tài liệu ở đây: https://developers.google.com/android-publisher/v1/purchases/get

Các dấu hiệu cho phép thời gian gần đây được làm mới (tự động). (Thông thường nó nói 401 khi nó cũ.)

[[email protected] 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. 
+0

Bạn đã giải quyết được sự cố này chưa? Tôi đã gặp phải vấn đề tương tự. – tszming

+0

Có, nhưng tôi không biết làm thế nào. Nó mới bắt đầu hoạt động. Tôi nghĩ rằng đó là một trong những điều sau đây: 1) Mã thông báo truy cập chỉ tốt trong một thời gian rất ngắn, có thể là 10 giây, vì vậy bạn phải sử dụng tập lệnh hoặc mã để xác thực và tìm nạp chi tiết liên tiếp. 2) Gói phải được xuất bản. 3) Mã thông báo đăng ký phải là thực và được thanh toán. 4) Id đăng ký phải được xuất bản. – Chloe

+0

có, có vẻ như Google đã khắc phục sự cố. – tszming

Trả lời

1

@imrankhan. Dưới đây là cách thực hiện trong 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; 
    } 
} 
Các vấn đề liên quan