要在订阅后获取订阅到期日期,需要按照以下步骤操作。
第 1 步:首先从以下 api Google Publisher API
获取“mRefreshToken”
第 2 步:
接下来需要使用 params("mRefreshToken", "client_id" and "client_secret") 和下面的 api 获取 "access_tokon"。
final StringRequest mStringRequest = new StringRequest(Request.Method.POST, "https://accounts.google.com/o/oauth2/token",
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
[From response -get access_tokon]
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<>();
params.put("grant_type", "refresh_token");
params.put("client_id", "your_client_id");
params.put("client_secret", "your_client_secret");
params.put("refresh_token", mRefreshToken);
return params;
}};
第 3 步:
您从上面的 api 获得“accessToken”,然后使用下面的 api 和参数获取到期 json
字符串 url = " https://www.googleapis.com/androidpublisher/v2/applications/ " + AppController.getInstance().getPackageName() + "/purchases/subscriptions/" + mSubscriptionId + "/" + "tokens/" + mPurchaseToken;
final StringRequest mStringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
[From response -get expiry detail json]
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("Authorization", "Bearer " + accessToken);
return params;
}};
更多参考:
来自谷歌的官方文档网址“ https://developers.google.com/android-publisher/api-ref/purchases/subscriptions/get ”和“ https://developers.google.com/android-publisher/授权“