Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

Commit

Permalink
Add API Key Parameter to OpenWeatherMap API Call
Browse files Browse the repository at this point in the history
  • Loading branch information
cdlei committed Oct 13, 2015
1 parent 30afc9f commit affe306
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle
Expand Up @@ -17,6 +17,9 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildTypes.each {
it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY', MyOpenWeatherMapApiKey
}
}

dependencies {
Expand Down
Expand Up @@ -144,12 +144,14 @@ protected Void doInBackground(String... params) {
final String FORMAT_PARAM = "mode";
final String UNITS_PARAM = "units";
final String DAYS_PARAM = "cnt";
final String APPID_PARAM = "APPID";

Uri builtUri = Uri.parse(FORECAST_BASE_URL).buildUpon()
.appendQueryParameter(QUERY_PARAM, params[0])
.appendQueryParameter(FORMAT_PARAM, format)
.appendQueryParameter(UNITS_PARAM, units)
.appendQueryParameter(DAYS_PARAM, Integer.toString(numDays))
.appendQueryParameter(APPID_PARAM, BuildConfig.OPEN_WEATHER_MAP_API_KEY)
.build();

URL url = new URL(builtUri.toString());
Expand Down

3 comments on commit affe306

@shabkal5a6
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it gave me this error
Error:(137, 107) error: cannot find symbol variable OPEN_WEATHER_MAP_API_KEY

when declaring OPEN_WEATHER_MAP_API_KEY in BUILDCONFIG.java it will be removed when I run the app and gave me the above error.
any hint??

@mathemandy
Copy link

@mathemandy mathemandy commented on affe306 Jun 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how i implemented mine! Hope this help
ss 1

The vaiable in the BuildConfig.java file was automatically generated from the build.gadle file :)
ss 2

@shabkal5a6
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice, it works. thanks.

Please sign in to comment.