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 ea6e195 commit d082c15
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
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

This comment has been minimized.

Copy link
@parthmahendra

parthmahendra Apr 3, 2016

Error:Cause: failed to find target with hash string 'android-21' in: C:\Users\Parth\AppData\Local\Android\sdk
Open Android SDK Manager

}
}

dependencies {
Expand Down
Expand Up @@ -126,7 +126,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
// Construct the URL for the OpenWeatherMap query
// Possible parameters are avaiable at OWM's forecast API page, at
// http://openweathermap.org/API#forecast
URL url = new URL("http://api.openweathermap.org/data/2.5/forecast/daily?q=94043&mode=json&units=metric&cnt=7");
String baseUrl = "http://api.openweathermap.org/data/2.5/forecast/daily?q=94043&mode=json&units=metric&cnt=7";
String apiKey = "&APPID=" + BuildConfig.OPEN_WEATHER_MAP_API_KEY;

This comment has been minimized.

Copy link
@hamedaravane

hamedaravane Nov 10, 2015

Cannot resolve symbol 'OPEN_WEATHER_MAP_API_KEY'

URL url = new URL(baseUrl.concat(apiKey));

// Create the request to OpenWeatherMap, and open the connection
urlConnection = (HttpURLConnection) url.openConnection();
Expand Down

14 comments on commit d082c15

@AmrHussien
Copy link

Choose a reason for hiding this comment

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

please I have an error with 'OPEN_WEATHER_MAP_API_KEY'

why it cannot resolve this symbol ?

@sahilbabbar
Copy link

Choose a reason for hiding this comment

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

Look out for the file where you are mentioning the API Key random string.

@mrizwan2018
Copy link

Choose a reason for hiding this comment

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

can not resolve symbol 'OPEN_WEATHER_MAP_API_KEY'
how can i solve it?

@mrizwan2018
Copy link

Choose a reason for hiding this comment

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

Cannot resolve symbol 'OPEN_WEATHER_MAP_API_KEY'
how can i solve it?

@Sinapse87
Copy link

Choose a reason for hiding this comment

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

@mrizwan2018 @AmrHussien have you added your key in your .gradle folder in your home?

@EConroyd
Copy link

Choose a reason for hiding this comment

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

Is the MyOpenWeatherMapApiKey supposed to be our personal key that we get from the weather website?

@parthmahendra
Copy link

Choose a reason for hiding this comment

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

My build.gradle file gives error when I try and sync it once I've added the key in:

Error:Cause: failed to find target with hash string 'android-21' in: C:\Users\Parth\AppData\Local\Android\sdk
Open Android SDK Manager
Am I doing something wrong?

UPDATE: I changed the version numbers to my current SDK version and now I get this error: Error:(27, 13) Failed to resolve: com.android.support:appcompat-v7:23.0.3
Install Repository and sync project
Show in File
Show in Project Structure dialog

The install doesn't seem to work

@Gabrielhmr
Copy link

Choose a reason for hiding this comment

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

@adriailla
Copy link

Choose a reason for hiding this comment

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

@Sinapse87 how can I do that?

@veraposeidon
Copy link

Choose a reason for hiding this comment

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

Replace MyOpenWeatherMapApiKey with your openweather API key. for example, if your key is 1111111, put ""1111111"" there.

@geelaro
Copy link

Choose a reason for hiding this comment

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

@EConroyd yeah, you are right.

@geelaro
Copy link

Choose a reason for hiding this comment

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

MyOpenWeatherMapApiKey defines in which file?

@yanghaiquanV5
Copy link

Choose a reason for hiding this comment

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

if your id is 111 , you should add buildConfigField "String", "OPEN_WEATHER_MAP_API_KEY", ""111""

@OssamaKrawi
Copy link

Choose a reason for hiding this comment

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

For those of you who are having problems with the OPEN_WEATHER_MAP_API_KEY, follow these steps:
1- Go to http://openweathermap.org/ and sign up or sign in.
2- Create your own API key in your account page.
3- Copy your API key and open your app build.gradle file in android studio.
4- Copy these lines:
buildTypes.each {
it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY', ""YOUR_KEY_HERE""
}
5- Make sure to include the backslash before each of the inner double quotes for your key to be parsed successfully. (I've included them for you, just copy and paste.)

That's it!

Please sign in to comment.