I am working on a project using WMATA (DC Metro) API and I need to retrieve some data such as stations names, pathing of two stations...
I have an API Key but I don't know to do the networking part.
Should WMATA return an OAuthToken? How can I send a request?
No, you don't need OAuthToken or any Auth method, you just need to send your api_key at request header. There are a lot of example on wmata documentation. You can use Java examples as a reference for Kotlin.
Look at the Java section bottom of this page and find this line:
request.setHeader("api_key", "{subscription key}");
Change
{subscription key}
with your API Key
Related
I'm developing an android app using android studio. I implemented web3j and successfully connected to ethereum using infura. I'm not sure how I can get the total supply of a specific coin.
Tried using the load method to load a specific tokens contract but was not able to get that to work.
Instead of using RPC nodes like Infura, I recommend that you use Moralis as it provides you with an easy API that you can call in Java. It's a basic REST API so you can call it in any other language too.
You can use this runContractFunction API here. And all you need to do is provide the input parameters as follows:
address: ERC20 token contract address
chain: the chain your ERC20 token exists
function_name: totalSupply
abi: the ABI of ERC20 token
Once you have all this setup, you'll be able to get the total supply in just a few lines of code.
Hope this helps out! :😊
I have a JSON API URL "http://myurl/getDataMethod" this takes a parameter "parameter1". How can I call this API in browser to view its result? Can I use JSFiddle to see the result on runtime? If not then can you provide code for viewing the result in Android app?
I tried calling the API in android App but I got error java.io.FileNotFoundException:, I don;t know why. Also my parameter is having # symbol which is getting converted to %40 when I call the URL through code in APP. I just want to view the data from this API by passing parameter, please help/advise. Thanks.
You can always use an API Tester tool like Postman for testing/viewing the response received from an API. Also if your API method is GET, you can even use a browser by passing the relevant query parameters.
When you try to call an API from a browser, the entire URL gets Encoded so # becomes %40
Use Postman software to access your api and its data anytime before you start coding so as to know the data structure and flow.
Refer to the Postman tutorials or official documentation to learn more about the working
Postman documentation link:
https://learning.getpostman.com/docs/postman/api-documentation/documenting-your-api/
I'm creating a payment android library(aar) and i have to make sure that all of the requests that i got in back-end are from my lib not a fake lib.
how can i do it?
I used two ways before:
1- Easy and bad way: Try to use a hardcoded String like JWT in your app and use a strong obfuscator to avoid decompiling the application.
2- Better way: You can use instance id and send it to your backend and server can inquire this id from the Google and there are some elements like package id in the response which server can use to accept or reject the request.
A sample response from the Google:
{
"application":"com.iid.example",
"authorizedEntity":"123456782354",
"platform":"Android",
"attestStatus":"ROOTED",
"appSigner":"1a2bc3d4e5",
"connectionType":"WIFI",
"connectDate":"2015-05-12
}
}
reference: https://developers.google.com/instance-id/reference/server
The app uses Google Cloud Messaging and contains a google-services.json file which itself contains Google API authentication info, including the API key. GCM functions as expected.
The app contains a testing facility that sends a GCM message using HTTP, and it needs the API key. How do I access that key, the one stored in google-services.json? I do not want to use GoogleCloudMessaging to send the messages (I'm using OkHttp and it does the job nicely).
Hopefully it is not necessary to duplicate it in the app.
Sorry, a bit late to the game here...
The google-services.json file gets parsed and its values get added to an xml which you have access to:
https://developers.google.com/android/guides/google-services-plugin
In your case, you could get the api key with:
activity.getResources().getString(R.string.google_api_key);
You can just get the API key off your GoogleCloud platform then go to credentials and you can grab your API key off of there.
https://console.developers.google.com/
Is that what your looking for?
But if you need to access it (which is should never change unless your change the json file itself) Then you could just parse the json file with a parser. But thats adding more work than needed. I would just copy and paste it from the web.
Ok I see what you going for try using this and using the NSDefualts
Store the token like this:
if (registrationToken != nil) {
self.registrationToken = registrationToken
print("Registration Token: \(registrationToken)")
//store the registation token for use in the postData function in the login page
self.loginInformation.setObject(self.registrationToken, forKey: "GCMToken")
let userInfo = ["registrationToken": registrationToken]
And retrieve it anywhere in the project like this:
myNoteGCMID = loginInformation.objectForKey("GCMToken") as! String
Then if it changes you don't have to change it in but just one place. The change will occur everywhere you call it.
I am a little confused by these APIs. I am trying to integrate Google+ with my Android app and I am struggling a little. I have been successful at logging in a user using OAuth2, created a Verifier, obtained an accessToken and made a request to Google+ API.
Here is my line of code requesting to see the user information:
OAuthRequest request = new OAuthRequest(Verb.GET, "https://www.googleapis.com/plus/v1/people/me");
This successfully returns a jSON object containing my information/public.
Whenever I change the endpoint to this:
"https://www.googleapis.com/plusDomains/v1/circles/p4643b3a289c42c44"
attempting to use the PlusDomains, I get a forbidden message.
What I really want to do is manage circles for a user (simply add a page to their "Following" circle. That is all I need.
What am I doing wrong? Am I trying to use the wrong endpoint? Does Google+ API allow me to do POST requests?
Every piece of information is helpful.
Thanks in advance!
Google+API and Google+Domains API are different APIs (activating/allowing one does not activate/allow the other).
The Domains API can be considered as a more powerfull (more functionnalities) than Google+API.
See comparison of the two API here on the official doc.
Link here