I am using Stripe's PaymentMethodActivity to add a payment source. When adding a credit card, I can debug all the way until this line of code in Stripe's AddSourceActivity:
CustomerSession.getInstance().addCustomerSource(
this,
source.getId(),
sourceType,
listener);
The listener callbacks never get called and the progress bar on the AddSourceActivity keeps going indeterminately. This was working before, but I suspect this issue may be related to our recent backend overhaul. Could there be an issue with the api version when creating the ephemeral key?
I found a solution. I wasn't correctly handling the response from our backend when requesting a new ephemeral key. Originally I had deserialized the response into an object and then converted that object to a json string to pass to Stripe. I corrected the problem by directly using the string representation of the response instead of doing any unnecessary serialization steps.
Related
I am experiencing some issues with a retrofit call to the backend. I explain you the situation:
I have developed the API call in the postman by the next way:
In the Android studio I try to do the API call by the next way:
#GET("restricted/GaiakIkuskatzea")
Call<Gaiak> getGaiak(#Query("grupo") String grupo);
But what I get is a empty object of JSON type, as I got if in the postman I make an api call without the param I showed before, and with the parameter specifyed in the body:
Does any of you know why I am having porblems with the Studio?
Thanks!
The final answer was watching the name that recived the data that you were receiving, in my case I put http and observed the mistake.
I want to use distance matrix by google. When I use postman for checking my URL, it works fine, it returns correct JSON. When I do the same thing in my android app, I receive request denied. I'm not restricitng my key, i do not autorize it, I want it to be public and I want to use it everywhere if possible. There are post 5 years old saying that I might be using web browser Api key, but I cannot find specific, android app manual for android api key generator. What I am doing wrong?
request denied
Another thing, I cannot change anything in my account, but I dont think these options matter since they are optional.
Failed to save
I'm using Retrofit:
#GET("maps/api/distancematrix/json")
Call<DistanceResponseModel> getDistanceModel2(#Query("origins") String origins,
#Query("destinations") String destinations,
#Query("key") String key);
I've activated APi in CloudConsole
i'm adding key to the request
APIs are no restricted or unauthorized
I also added key to manifest and gradle with THIS manual
I was using http instead of https in my serivce generator. So yeah, lol.
I need to connect my Android application with Facebook Analytics, using custom events.
I followed official documentation on https://developers.facebook.com/docs/analytics/
Added facebook SDK into the project:
implementation 'com.facebook.android:facebook-android-sdk:5.15.3'
Generated all the necessary hashes, put everything necessary in the Manifest, all good.
App was built and launched, however, events were never showing up in the Analytics Console.
After hours and hours of debugging, I've found the problem.
Inside Facebook SDK library code, when postRequest to server is created, it has (among others) parameter called "extInfo". This parameter should contain json array with strings, in certain order.
Now, that's how Facebook SDK postRequest looks, when sent from the application:
As you can see, extinfo json array is all contaminated with backslashes. When I replicated this request manually in Postman, server returned error:
"message": "(#100) Field extinfo must be a valid json object with string keys"
So, in Postman, I modified extinfo parameter - cleaned it out of backslashes:
Result from server in this case is: "success": true. Events started appearing inside Analytics Dashboard.
Wonderful. But.
How to send events with the help of Facebook SDK, considering this bug? Is there sdk version where this bug doesn't appear? Is there a way to tune sdk so that it doesn't send extinfo at least?
Any other possible solution, except for sending requests without help of Facebook SDK (that's a whole load to write, besides, if they change request structure, code has to be re-written)?
I haven't found metions of this bug anywhere in the Internet. If there is, please share a link. Thank you.
Edit: tried with implementation 'com.facebook.android:facebook-core:7.1.0' too. No luck.
I've found the solution. In my case, problem was inside the project and had nothing to do with Facebook SDK.
Previous developer created validation for hosts that application can use:
HttpsURLConnection.setDefaultSSLSocketFactory(socketFactory)
val verify = fun(ip: String, _: SSLSession): Boolean {
println(ip)
return ip.contains("crashlytics", true) ||
ip.contains("firebase", true) ||
ip.contains("maps.googleapis.com", true) ||
ip.contains("facebook.com", true)
}
HttpsURLConnection.setDefaultHostnameVerifier(verify)
Once I added facebook.com in the list, error was gone. However, I still don't understand why in the log "extinfo" parameter was generated with backslashes.
I'm using Retrofit with OKHttp client for caching responses from a JSON API.
This works nicely.
However, if I take an action on the device which causes the data to update on the server I need a way to 'invalidate' a particular route in order to ensure that next time a request is made for this data, it is fetched from the server again rather than the now outdated cached version.
Currently, I've worked around this by explicitly calling the new route with a "no-cache" flag in the Cache-Control header of the request, but this forces me to download the new data before it is needed, potentially multiple times if multiple actions are taken, just to keep the cache up to date.
Is there a way I can mark a route / method in my retrofit/OKhttp client as cache expired, requiring a mandatory update over the network the next time it's requested?
With retrofit2 and OkHttp3 you can force a new response by adding a Cache-Control header to your API method definition parameters:
#GET("ws/something")
Something getSomething(#Header("Cache-Control") String cacheControl);
and then when calling you either supply null for a (maybe-)cached version or "no-cache" for a live version:
myApi.getSomething(forceRefresh ? "no-cache" : null);
This is now possible in OkHttp by using the Cache.urls() function. As the documentation says:
The iterator supports Iterator.remove(). Removing a URL from the
iterator evicts the corresponding response from the cache. Use this to
evict selected responses.
This was merged into master late December 2014 and seems to be part of these tags (releases): parent-2.4.0-RC1 parent-2.4.0 parent-2.3.0 parent-2.2.0
There isn't an API for this, but there should be one. Please open an OkHttp issue to report this.
It'll probably take a while for us to implement because we'll need to figure out what the best API for this is. Invalidating a single URL is straightforward. Invalidating a range of URLs (say square.com/cash/*) is more difficult because OkHttp's cache is currently organized by URL checksums. There's also ugly edge cases like what happens if the invalidated URL is currently being written to the cache.
To quote the official code sample using urls():
val urlIterator = cache.urls()
while (urlIterator.hasNext()) {
if (urlIterator.next().startsWith("https://www.google.com/")) {
urlIterator.remove()
}
}
I'm trying to make an app that accesses a user's Google Calendar using OAuth. I have the code in place that gets all of the proper tokens and they are saved into some preferences. I used the tutorial here to do this all, by the way. I have successfully changed the scope and request URL's so that I'm getting the needed tokens. The problem comes when I actually try to USE the token. Instead of calendar info, I get back some HTML that says "Unknown authorization header Error 401". The request URL I am using is:
https://www.google.com/calendar/feeds/default/allcalendars/full
and the scope is:
http://www.google.com/calendar/feeds/
I have tried replacing 'default' with my email address (which is also the one that I used for the OAuth) to no avail. Am I using the wrong URL? if not, what else could cause this error? I have been looking for a few days now to find someone who has accessed the Calendar using OAuth, but everything I have found is people giving up because it's too difficult or doesn't work.
EDIT:
I believe my header is correct, here is an example of it:
OAuth oauth_token="************-********-**********-****",
oauth_consumer_key="anonymous",
oauth_version="1.0",
oauth_signature_method="HMAC-SHA1",
oauth_timestamp="1303161387",
oauth_nonce="*******************",
oauth_signature="*******************"
That is pulled directly from my app, and from what I could find it looks right to me, but I'm still getting the error above (Unknown Authorization Header Error 401).
The Authorization header needs to be "Authorization: OAuth oauth_nonce="deadbeefdeadbeef" oauth_version="1.0" ....
See http://code.google.com/apis/accounts/docs/OAuth_ref.html#RequestToken. You can, supposedly, also but the authorization parameters in the querystring or in the body of a POST, but I have not attempted that.
As noted in the comments below, Google is now, at least with the Calendar feed, appending a 'gsessionid=' querystring and redirecting; and so a redirect handler must create a new nonce and timestamp, and make a new signature making sure to add the gsessionid to the base signature string in the correct lexicographical order (preceding any of the oauth_ variables).