Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialLiz Kester
1,295 PointsHow to enter an API key as a query parameter (for AccuWeather)?
Because DarkSky is no longer available, I am using AccuWeather. However, their URl does not have a place for the API key. The url for the 5-day forecast looks like this: http://dataservice.accuweather.com/forecasts/v1/daily/5day/{36866_PC} the apikey is a required query parameter for the request to have a response with the forecast data. I have tried created an HttpUrl object and using .addQueryParameter('apikey', 'my api key here'), and then using that in the Request object, but I don't get any readout of my log in logcat. The app installs successfully but no information is returned.
1 Answer
Lewis Sneddon
2,505 PointsA query parameter is added on the end of the url string like so; '?paramName=paramValue'. To add more than one, separate with a '&'. try putting your api key and other params into 'postman.com' or accuweather probably have an option to build a request url by putting your parameters in, look for cURL (this is usually a curl command to use on your terminal, but just miss that bit out and take the url) I spent ages trying to debug this before realising that my physical device didn't have wifi set up, so that's something to check too lol