I have in Google in app billing set up in my app using the IabHelper classes from the trivialdrive sample app. I can successfully purchase items, and now I'm trying to implement server side verification.
I see in Security.java that there is a verifyPurchase method.
https://code.google.com/p/marketbilling/source/browse/v3/src/com/example/android/trivialdrivesample/util/Security.java
I want to replace that with a call to my server that will do the verification on the server vs on the client device. I have my endpoint set up and working.
I'm stuck at how to call my endpoint and have verifyPurchase return true or false based on the response. I currently use Volley which makes async calls. I can get my endpoint's response in Volley's success callback. But since that network call is async, I'm not sure how to return true or false in verifyPurchase based on that call's response. I'm a java n00b :)
Create an interface call that in response of the async call of volley use that. Implement that interface in that class where you need your verifyPurchase() return. Override that interface and process the response.
Related
I'm trying to use RxJava in my Android application, along with Retrofit, to interact with a RESTful API.
In my Android app I sent out a number of requests at various UX events. If one of the request returns an 'Invalid Token' error, I want to pause any other requests that get queued before they start so that I can renew the user's token, and then resume the paused requests.
Is this possible using RxJava? I'm just learning the library and am having trouble finding this functionality.
Thanks,
If these requests are sent in parallel, then you will likely get multiple "Invalid Token" errors. You would want to refresh the token for only the first instance of the error. To pause requests while the token is being refreshed, think about the source of the valid token being an observable.
Let's assume you have a network handling class that has methods:
Single<Response> makeNetworkRequest(Request request) { ... }
Single<Boolean> getToken() { ... }
It is implemented such that a value is emitted when a token is available, but otherwise waits until the token is refreshed.
Then, your observer chain will look something like:
observerChain
.flatMapSingle(request -> networkHandler.makeNetworkRequest(request)
.retryWhen(error -> error.flatMapSingle(e -> networkHandler.getToken()))
...
The retryWhen() operator recovers from the error by providing an observable that, when non-empty, will resubscribe to the upstream observable, in this case, the makeNetworkRequest().
Since you don't show any of your code that you are trying to adapt, you will have to make adjustments to the code above to get it to work with your application.
At the time of login we get a authorization token and a refresh token,authorization token is attached with all API in header ,but after some time authorization token will expire and we will get 401,to refresh we need to call a API with refresh token that we get at the time of login in response we will get a new authorization token and refresh token,problem is where to catch 401 and write at one point to call refresh token API and resend the previous failed API ,we cant call API in interceptor.
Check this Refresh Access Token globally (Separate logic as a module) using RxJava 2, RxAndroid 2 and Retrofit 2 post.
Maybe it will help you
Okhttp (which acts as the http layer of retrofit) has a mechanism for doing just this. Have a look at https://square.github.io/okhttp/4.x/okhttp/okhttp3/-authenticator/
You provide the Authenticator to your Okhttp builder during setup and this then responds to 401 error responses to fetch a refresh token.
I know that React Native uses JS way of doing things ie making function calls asynchronous. So this also applies to API "fetch" function. However, for some reason, I need to make API "fetch" synchronous.
This is what I want to do. The app has a listing of items. It has to loop through the items and for each of them, I need to construct the URL and then call "fetch" based on constructed URL to get the response (eg if I have 5 items, it would call the API 5 times, where each URL called has different parameters). Once I have successfully received responses for all of the listing items, then I need to do something else, such as updating some state (the state is dependent on having all of the responses returned).
Note that I have no control over the backend ie unable to change the URL side to have batch calls instead.
Question is, how do I make sync call in React Native?
You can call synchronously by using XMLHttpRequest object.
var request = new XMLHttpRequest();
request.open('GET', 'https://mywebsite.com/endpoint.php', false); // third parameter FALSE makes Synchronous HTTP request
request.send(null);
if (request.status === 200) {
console.log(request.responseText);
}
or
you will get many npm modules that will provide synchronous api call.
i hope this will help you.
Would like to use Retrofit for handling network requests between Android Client and GAE endpoints.
GAE endpoints give Client/Server endpoint libraries to handle all the networking and also Oauth2 authentication which is nice.
Retrofit helps well for asynchronous call, cancellation, parallel calls...so is better than android client asynctask.
So can this Retrofit lib be configured with Appengine GAE endpoints or need to go through normal GAE servlet?
Just to clarify my question and make answers clear for any who read this :
I had for my App :
Client side : cloud endpoint library generated by google plug in for eclipse
Back end side GAE : different API with methods coded in JPA such as :
#ApiMethod(name = "insertMyShareItem")
public ShareItemData insertMyShareItemData(ShareItemData shareitemdata) {
logger.log(Level.SEVERE, "insertMyShareItem");
}
Advantages of google cloud endpoint was endpoint libray , easy use of Auth2 and automatically use of secure connections via HTTPS
Now I want to give up Async task in order to implement Retrofit or Volley. I understood I cannot use google cloud endpoint anymore and need to transform my methods on GAE Back end side in methods which extends HttpServlet so I can access them by URL call with normal setup of Retrofit.
Which means now I need to care :
how I pass my object to Retrofit and how I retrieve them on back end
how I transform Retrofit HTTP call in a HTTPS call for secure connection
how I implement and manage Auth2 and tokens between Client and GAE back end to establish secure authentication.
This is what I understood from search and below answers.Thks
Use the Google Cloud API URL as the base URL and proceed with the normal setup of Retrofit. I don't think it is a big deal. Here is a link to a tutorial that could help you get started with Retrofit.
[source]
How can I get an authentication for a URL, to which we have to send a request using Retrofit?
This depends on the the authentication method used by the service server.
For example, Twitch.tv provides "Authorization Code Flow" as one of the methods for authentication. In this method you provide the auth parameters in the request URL:
https://api.twitch.tv/kraken/oauth2/authorize
?response_type=code
&client_id=[your client ID]
&redirect_uri=[your registered redirect URI]
&scope=[space separated list of scopes]
Other methods requires specifying the auth parameters in the request header.
If you provide me with more information, regarding the authentication method used by the service you want to talk to, I may be able to provide you with a specific answer, or even with working code (If I have the time).