I am a new Xamarin developer. I am trying to integrate a data API to my Xamarin forms cross-platform mobile app.
Following is the site that I get my URL endpoint: navigate to the website
Following is the API endpoint I get from the above site: https://api.tidesandcurrents.noaa.gov/api/prod/datagetterdate=latest&station=8518750&product=air_temperature&datum=MTL&time_zone=gmt&units=metric&format=json
The API endpoint URL sends back data when based on the weather station IDparameter in the API endpoint. The problem is that it is hardcoded in the API endpoint itself. Therefore, I must change the whole API endpoint when I need to request data from another weather station ID.
I have no idea how to send the stationID as a variable in the same URL, like in following end point I got from openweather API service:
http://api.openweathermap.org/data/2.5/weatherlat{location.Latitude}&lon{location.Longitude}&appid=d6533ef259a2c612eb50836b198fc366&units=metric
In the above API, I can send the longitude and latitude as parameters via the API key and get relevant information. But in my API key, I cannot see such a way to send a 'StationID' as a parameter.
Can somebody please help me to modify my following code to send the 'stationID' as a variable and get data dynamically based on the station ID please?
Following is my code for getting API data send them to the .xaml front end.
private async void GetTideInfo()
{
var url = $"https://api.tidesandcurrents.noaa.gov/api/prod/datagetter?date=latest&station=8518750&product=air_temperature&datum=MTL&time_zone=gmt&units=metric&format=json";
var result = await ApiCaller.Get(url);
if (result.Successful)
{
var tidalInfo = JsonConvert.DeserializeObject<TidleRoot>(result.Response);
meanTideTxt.Text = tidalInfo.data[0].v + " m";
}
else
{
await DisplayAlert("Tidal data", "No tidal data found", "OK");
}
}
Thanks in advance for everybody who volunteer to solve my problem.
just insert the StationID value into the url
var stationId = 8518750;
var url = $"https://api.tidesandcurrents.noaa.gov/api/prod/datagetterdate=latest&station={stationId}&product=air_temperature&datum=MTL&time_zone=gmt&units=metric&format=json";
Related
I'm trying to write a react native app which will stream some tracks from Soundcloud. As a test, I've been playing with the API using python, and I'm able to make requests to resolve the url, pull the playlists/tracks, and everything else I need.
With that said, when making a request to the stream_url of any given track, I get a 401 error.
The current url in question is:
https://api.soundcloud.com/tracks/699691660/stream?client_id=PGBAyVqBYXvDBjeaz3kSsHAMnr1fndq1
I've tried it without the ?client_id..., I have tried replacing the ? with &, I've tried getting another client_id, I've tried it with allow_redirects as both true and false, but nothing seems to work. Any help would be greatly appreciated.
The streamable property of every track is True, so it shouldn't be a permissions issue.
Edit:
After doing a bit of research, I've found a semi-successful workaround. The /stream endpoint of the API is still not working, but if you change your destination endpoint to http://feeds.soundcloud.com/users/soundcloud:users:/sounds.rss, it'll give you an RSS feed that's (mostly) the same as what you'd get by using the tracks or playlists API endpoint.
The link contained therein can be streamed.
Okay, I think I have found a generalized solution that will work for most people. I wish it were easier, but it's the simplest thing I've found yet.
Use API to pull tracks from user. You can use linked_partitioning and the next_href property to gather everything because there's a maximum limit of 200 tracks per call.
Using the data pulled down in the JSON, you can use the permalink_url key to get the same thing you would type into the browser.
Make a request to the permalink_url and access the HTML. You'll need to do some parsing, but the url you'll want will be something to the effect of:
"https://api-v2.soundcloud.com/media/soundcloud:tracks:488625309/c0d9b93d-4a34-4ccf-8e16-7a87cfaa9f79/stream/progressive"
You could probably use a regex to parse this out simply.
Make a request to this url adding ?client_id=... and it'll give you YET ANOTHER url in its return json.
Using the url returned from the previous step, you can link directly to that in the browser, and it'll take you to your track content. I checked on VLC by inputting the link and it streams correctly.
Hopefully this helps some of you out with your developing.
Since I have the same problem, the answer from #Default motivated me to look for a solution. But I did not understand the workaround with the permalink_url in the steps 2 and 3. The easier solution could be:
Fetch for example user track likes using api-v2 endpoint like this:
https://api-v2.soundcloud.com/users/<user_id>/track_likes?client_id=<client_id>
In the response we can finde the needed URL like mentioned from #Default in his answer:
collection: [
{
track: {
media: {
transcodings:[
...
{
url: "https://api-v2.soundcloud.com/media/soundcloud:tracks:713339251/0ab1d60e-e417-4918-b10f-81d572b862dd/stream/progressive"
...
}
]
}
}
...
]
Make request to this URL with client_id as a query param and you get another URL with that you can stream/download the track
Note that the api-v2 is still not public and the request from your client probably will be blocked by CORS.
As mentioned by #user208685 the solution can be a bit simpler by using the SoundCloud API v2:
Obtain the track ID (e.g. using the public API at https://developers.soundcloud.com/docs)
Get JSON from https://api-v2.soundcloud.com/tracks/TRACK_ID?client_id=CLIENT_ID
From JSON parse MP3 progressive stream URL
From stream URL get MP3 file URL
Play media from MP3 file URL
Note: This link is only valid for a limited amount of time and can be regenerated by repeating steps 3. to 5.
Example in node (with node-fetch):
const clientId = 'YOUR_CLIENT_ID';
(async () => {
let response = await fetch(`https://api.soundcloud.com/resolve?url=https://soundcloud.com/d-o-lestrade/gabriel-ananda-maceo-plex-solitary-daze-original-mix&client_id=${clientId}`);
const track = await response.json();
const trackId = track.id;
response = await fetch(`https://api-v2.soundcloud.com/tracks/${trackId}?client_id=${clientId}`);
const trackV2 = await response.json();
const streamUrl = trackV2.media.transcodings.filter(
transcoding => transcoding.format.protocol === 'progressive'
)[0].url;
response = await fetch(`${streamUrl}?client_id=${clientId}`);
const stream = await response.json();
const mp3Url = stream.url;
console.log(mp3Url);
})();
For a similar solution in Python, check this GitHub issue: https://github.com/soundcloud/soundcloud-python/issues/87
https://developer.here.com/documentation/maps/dev_guide/topics/routing.html
{"error":"Unauthorized","error_description":"ApiKey invalid. ApiKey not found."}
I am using here maps api for routing and it's showing api key error key not found when i am passing key parameter in json format
// Instantiate a map and platform object:
var platform = new H.service.Platform({
'apikey': '{YOUR_APIKEY}'
});
The maps is working find when i pass the key as simple string i don't know if there is any error in documentation or at the api please update this on your site and check it once
the working code is below:
// Instantiate a map and platform object:
var platform = new H.service.Platform({
'apikey': 'YOUR_APIKEY'
});
just remove "{}" and it is working find
you should take your request and paste it on google search (the webpage search top bar). Remove any questionmark in the end, and you will see it will work, and will re-format the request. Copy the request from Google and try it on Postman now; hopefully it will work...
It worked for me.
We have programmed in android to track omniture using page name using the code
Analytics.trackState(pageName, params);
The params contains lot if data like s.channel, s.prop, Prop, s.eVar
Now: We want get all the params which got recorded in omniture by hitting this link
I am trying to use the nomniture module to call Report, but it is very difficult to understand the parameters to choose a particular page
My Node.js Code
var Client = require('omniture').Client, c = new Client(username,
sharedSecret, 'sanJose'), reportData = {
"rsid_list" : [ reportSuiteId ]
}
How to use s.pageName in a request to retrieve the recorded variables for a particular custom page name
I tried to use Report.QueueTrended, Report.QueueOvertime, Report.QueueRanked followed by Report.Get but I am not getting anything
I always ended up getting errorCode 5003, The report may contain imcomplete data. Please try again later
I am a complete newbie to webservices but have some experience in Java. We have been provided with Liverail API documentation with a list of Entities that we can consume. This is what their doc says:
"Logical flow An API client must always use the /login method followed by the /set/entity method. All the remaining APIcalls will be executed on the selected entity. If you need to switch the current entity, you should use /unset/entity followed by a new /set/entity with the new entity ID as parameter. It is also recommended to call /logout once the API client ends its execution"
XML response format
The LiveRail API XML response is always formated like bellow.
My dilema is that i dont know how to make the GET calls.
What i would like to do in java is :
Create a http login to API webservices
Fetch a list of data (response is in XML format)
3 Convert this XML response into CSV file.
Any help will be highly appreciated.
Why not using RestTemplate?
final String uri = "http://localhost:8080/springrestexample/employees/{id}";
Map<String, String> params = new HashMap<String, String>();
params.put("id", "1");
RestTemplate restTemplate = new RestTemplate();
EmployeeVO result = restTemplate.getForObject(uri, EmployeeVO.class, params);
System.out.println(result);
Here is for more tutorials http://howtodoinjava.com/2015/02/20/spring-restful-client-resttemplate-example/
in Apps Script, I would like to fetch click statistics for previously generated short URLs via the Google URL shortener API.
I'm afraid I don't really get the API documentation. This is what I tried:
function GetShortUrlClicks() {
var analytics = UrlShortener.Url.get('http://goo.gl/WPN7wo').getAnalytics();
var clicks = analytics.getAllTime();
Logger.log(clicks)
}
It seems that the variable analytics is undefined and thus the next line throws an error.
Any help is much appreciated.
You are missing the optional args required to get the Analytics data back.
This function ought to work -
function GetShortUrlClicks() {
var analytics = UrlShortener.Url.get('http://goo.gl/WPN7wo',{projection:'FULL'}).getAnalytics();
var clicks = analytics.getAllTime();
Logger.log(clicks)
}
You can use more see more reference here - https://developers.google.com/url-shortener/v1/url/get