我们正在Android中使用应用内购买实现订阅,我们正在获取以下格式的购买时间戳
'{
"orderId":"GPA.1234-5678-9012-34567",
"packageName":"com.example.app",
"productId":"exampleSku",
"purchaseTime":1345678900000,
"purchaseState":0,
"developerPayload":"bGoa+V7g/yqDXvKRqq+JTFn4uQZbPiQJo4pf9RzJ",
"purchaseToken":"opaque-token-up-to-1000-characters"
}'
但我们需要在应用程序UI中显示到期日期,我们希望从Play商店获得确切的到期日期。我们假设如果我们手动计算到期日,那么它可能与游戏商店到期日冲突。任何人都可以解释“如何在Android中获得Subscription的到期日期?”
答案 0 :(得分:5)
要在订阅后获取订阅到期日,需要按照以下步骤操作。
第1步: 首先从以下api Google Publisher API
获取“mRefreshToken”第2步: 接下来需要使用params(“mRefreshToken”,“client_id”和“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和params获得到期的json
String 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;
}};
有关详情: 来自Google“https://developers.google.com/android-publisher/api-ref/purchases/subscriptions/get”和“https://developers.google.com/android-publisher/authorization”
的官方文档网址答案 1 :(得分:-1)
我尝试使用此API“ https://www.googleapis.com/androidpublisher/v2/applications/” + AppController.getInstance()。getPackageName()+“ / purchases / subscriptions /” + mSubscriptionId +“ /” +“ tokens /” + mPurchaseToken;
具有正确的有效数据,但我发现了此错误:
**{
"error": {
"errors": [
{
"domain": "androidpublisher",
"reason": "permissionDenied",
"message": "The current user has insufficient permissions to perform the requested operation."
}
],
"code": 401,
"message": "The current user has insufficient permissions to perform the requested operation."
}
}**
请告诉我是否有解决方案。我按照所有步骤操作,并使用Play控制台和Google Cloud Console帐户完成了所有操作。