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