Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Dec 30, 2024. It is now read-only.

Commit 89d631e

Browse files
committed
Add missing imports, move getAccessToken above smoke test
1 parent 1515c26 commit 89d631e

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

admin/src/main/java/com/google/firebase/example/FirebaseRemoteConfigSnippets.java

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
import com.google.firebase.remoteconfig.Template;
3030
import 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;
3237
import java.io.FileInputStream;
3338
import java.io.IOException;
3439
import 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

Comments
 (0)