Question

I've an android application and it's using the "Google Play In-app Billing" library to purchase in-app.

I've read that is better to verify purchases in a backend server using the Purchase Status API (Google Play Android Developer API v1.1).

I've found an example about how to obtain the refresh token, how to use it to obtain a access token, and how to use the API.

        System.getProperties().put("http.proxyHost", "10.12.54.8");
        System.getProperties().put("http.proxyPort", "8080");

        HttpTransport HTTP_TRANSPORT = new NetHttpTransport();              

        JsonFactory JSON_FACTORY = new JacksonFactory();

        TokenResponse tokenResponse = new TokenResponse();
        tokenResponse.setAccessToken(accessToken);
        tokenResponse.setRefreshToken(refreshToken);
        tokenResponse.setExpiresInSeconds(3600L);

        tokenResponse.setScope("https://www.googleapis.com/auth/androidpublisher/v1.1/applications");
        tokenResponse.setTokenType("Bearer");

        HttpRequestInitializer credential = new GoogleCredential.Builder().setTransport(HTTP_TRANSPORT).setJsonFactory(JSON_FACTORY)
                .setClientSecrets(GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET).build().setFromTokenResponse(tokenResponse);

        AndroidPublisher publisher = new AndroidPublisher.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName(GOOGLE_PRODUCT_NAME).build();                    

        AndroidPublisher.Inapppurchases purchases = publisher.inapppurchases();
        Get get = purchases.get(GOOGLE_PACKAGE_NAME, ITEM_ID, purchaseToken);
        InappPurchase purch = get.execute();

But I'm not able to connect to google, probably because I am behind a proxy. I don't know how to configure the proxy settings when I use these classes.

The error obtained is:

java.net.SocketTimeoutException: connect timed out

Please help!

Was it helpful?

Solution

I've found a solution.

Instead of NetHttpTransport, use ApacheHttpTransport like this:

HttpHost proxy = new HttpHost("10.12.54.8", 8080, "http");
HttpClient client = new DefaultHttpClient();
client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
ApacheHttpTransport HTTP_TRANSPORT = new ApacheHttpTransport(client);       

Now I'm getting a different error (404 Not found), but this is a different issue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top