简体   繁体   中英

Google API call fails from an ASP.NET Web API application hosted on shared Windows hosting server

I have created an ASP.net Web API application. This application has an API that receives sku Id and purchase token from my Android app, verifies the purchase and returns an appropriate result. Now, the issue is, when I run my application locally, it runs fine. Google returns me a response and I can process it. But when I host this application on my shared Windows hosting server, this call fails. It simply fails, there is no error.

Here is my Web API.

[HttpPost]
[Route("Api/Files/GetFiles")]
public HttpResponseMessage GetFiles(FileInfo fileInfo)
{
    string skuId = fileInfo.SkuId;
    string purchaseToken = fileInfo.PurchaseToken;
    ProductPurchase productPurchase = GoogleAPIConnector.GetProductPurchaseInfo(skuId, purchaseToken);
}

Here is the 'GetProductPurchaseInfo' function.

public static ProductPurchase GetProductPurchaseInfo(string productId, string purchaseToken)
        {
            string packageName = "my.package.name";

            string sFileContents = "my p12 file contents as a byte array";

            byte[] baFileContents = Convert.FromBase64String(sFileContents);

            var certificate = new X509Certificate2(baFileContents,
                            "notasecret",
                            X509KeyStorageFlags.Exportable | X509KeyStorageFlags.MachineKeySet
                        );

            var credentials = new ServiceAccountCredential(
                    new ServiceAccountCredential.Initializer("my publisher account on google play service")
                    {
                        Scopes = new[] { AndroidPublisherService.Scope.Androidpublisher }
                    }.FromCertificate(certificate));

            var service = new AndroidPublisherService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credentials,
                ApplicationName = "my application name",
            });

            return service.Purchases.Products.Get(packageName, productId, purchaseToken).Execute();
        }

I am at my wits end trying to find a solution. Can this be because API calls are prohibited in a shared hosting environment? I think this can be the only reason because this call is successful when the application is run locally. Or am I missing some configuration on the server?

I was able to fix this issue by changing my web hosting provider. I went with Accuwebhosting. I deployed my code, called the API using Postman and was able to get a response.

So, this was GoDaddy's fault. (One more reason to hate them?)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM