Skip to content

Commit 9dc5ddc

Browse files
authored
Update OnlinePredictionSample.java (GoogleCloudPlatform#1557)
* Update OnlinePredictionSample.java * Update OnlinePredictionSample.java
1 parent 82790c1 commit 9dc5ddc

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

mlengine/online-prediction/src/main/java/OnlinePredictionSample.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import com.google.api.services.discovery.model.RestDescription;
3131
import com.google.api.services.discovery.model.RestMethod;
3232
import java.io.File;
33+
import java.util.ArrayList;
34+
import java.util.List;
3335

3436
/*
3537
* Sample code for sending an online prediction request to Cloud Machine Learning Engine.
@@ -61,8 +63,11 @@ public static void main(String[] args) throws Exception {
6163
File requestBodyFile = new File("input.txt");
6264
HttpContent content = new FileContent(contentType, requestBodyFile);
6365
System.out.println(content.getLength());
64-
65-
GoogleCredential credential = GoogleCredential.getApplicationDefault();
66+
67+
List<String> scopes = new ArrayList<>();
68+
scopes.add("https://www.googleapis.com/auth/cloud-platform");
69+
70+
GoogleCredential credential = GoogleCredential.getApplicationDefault().createScoped(scopes);
6671
HttpRequestFactory requestFactory = httpTransport.createRequestFactory(credential);
6772
HttpRequest request = requestFactory.buildRequest(method.getHttpMethod(), url, content);
6873

0 commit comments

Comments
 (0)