最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

See if a user has bought an app in Google Play store, from website (.NET 8) - Stack Overflow

programmeradmin4浏览0评论

A bit of background: I have an app that I have published in Google Play. I also have a website where I want to give access to those who have bought the app.

I have already set up the login with the users Google account. But I fail to understand how to get the information if a specific Google account has bought my app.

In the backend application (on .NET 8) I have tried with the following code:

public async Task<bool> GetGooglePurchaseStatus(string email)
{
    string packageName = "com.packagename";
    string productId = "xxxxxxxxxxxxxxxxxxxx"; 

    string fileName = "gapi.json";
    string folderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Assets");
    string filePath = Path.Combine(folderPath, fileName);

    var credential = GoogleCredential.FromFile(filePath);
    var service = new AndroidPublisherService(new BaseClientService.Initializer
    {
        HttpClientInitializer = credential,
        ApplicationName = packageName
    });

    var request = service.Purchases.Products.Get(packageName, productId, email);
    var purchase = await request.ExecuteAsync();

    return purchase.PurchaseState == 0; // 0 means purchased
}

When I run this I get the following error:

The service androidpublisher has thrown an exception.

HttpStatusCode is Unauthorized.
Google.Apis.Requests.RequestError
The current user has insufficient permissions to perform the requested operation. [401]
Errors [
Message[The current user has insufficient permissions to perform the requested operation.] Location[ - ] Reason[permissionDenied] Domain[androidpublisher]
]

I'm quite sure that I'm missing something in the setup in Google Cloud and/or in Google Play Console..

What permissions do I need to set, and where?

I have created new project in Google Cloud, and a service account from where I downloaded the json file with the credentials

发布评论

评论列表(0)

  1. 暂无评论