2929import com .google .firebase .remoteconfig .Template ;
3030import com .google .firebase .remoteconfig .Version ;
3131
32+ import java .io .IOException ;
33+ import java .net .HttpURLConnection ;
34+ import java .net .URL ;
35+ import java .util .Arrays ;
36+ import java .util .List ;
3237import java .io .FileInputStream ;
3338import java .io .IOException ;
3439import java .util .concurrent .ExecutionException ;
@@ -181,6 +186,23 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc
181186 System .exit (1 );
182187 }
183188
189+ /**
190+ * Retrieve a valid access token that can be use to authorize requests to the Remote Config REST
191+ * API.
192+ *
193+ * @return Access token.
194+ * @throws IOException
195+ */
196+ // [START retrieve_access_token]
197+ private static String getAccessToken () throws IOException {
198+ GoogleCredentials googleCredentials = GoogleCredentials
199+ .fromStream (new FileInputStream ("service-account.json" ))
200+ .createScoped (Arrays .asList (SCOPES ));
201+ googleCredentials .refreshAccessToken ();
202+ return googleCredentials .getAccessToken ().getTokenValue ();
203+ }
204+ // [END retrieve_access_token]
205+
184206 // Smoke test
185207 Template template = getRemoteConfig ();
186208 template .getParameterGroups ().put ("new_menu" , new ParameterGroup ());
@@ -194,20 +216,4 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc
194216 System .out .println ("Done!" );
195217 }
196218
197- /**
198- * Retrieve a valid access token that can be use to authorize requests to the Remote Config REST
199- * API.
200- *
201- * @return Access token.
202- * @throws IOException
203- */
204- // [START retrieve_access_token]
205- private static String getAccessToken () throws IOException {
206- GoogleCredentials googleCredentials = GoogleCredentials
207- .fromStream (new FileInputStream ("service-account.json" ))
208- .createScoped (Arrays .asList (SCOPES ));
209- googleCredentials .refreshAccessToken ();
210- return googleCredentials .getAccessToken ().getTokenValue ();
211- }
212- // [END retrieve_access_token]
213219}
0 commit comments