Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Build a Weather App Concurrency and Error Handling Making Our Code Asynchronous

How 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

A 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