我试图用java连接Google BigQuery,但得到了以下错误?
//错误- 找不到 线程main com.google.api.client.http.HttpResponseException中出现异常:未找到404 位于com.google.api.client.http.HttpRequest.executeHttpRequest.java:209 在BigQuerySample.mainBigQuerySample.java:25*/ //这是我的密码我试图用java连接Google BigQuery,但得到了以下错误?,java,google-bigquery,Java,Google Bigquery,//错误- 找不到 线程main com.google.api.client.http.HttpResponseException中出现异常:未找到404 位于com.google.api.client.http.HttpRequest.executeHttpRequest.java:209 在BigQuerySample.mainBigQuerySample.java:25*/ //这是我的密码 您正在查询一个不存在的URL。转到返回Not Found,这是异常告诉您的。请使用有效的URL,然
您正在查询一个不存在的URL。转到返回Not Found,这是异常告诉您的。请使用有效的URL,然后查看您的代码是否正常。您的代码可能完全没有问题。Google BigQuery不支持ClientLogin auth。您从哪里获得该样本的?查看此链接。从这里我找到了这个示例程序。。如果你有什么解决办法,请告诉我?谢谢,如果你注意到了,这是在遗留和不推荐的方法下。ClientLogin不支持对BigQuery进行身份验证。您需要使用OAuth2。看见
import com.google.api.client.googleapis.*;
import com.google.api.client.googleapis.auth.clientlogin.*;
import com.google.api.client.googleapis.json.*;
import com.google.api.client.http.*;
import java.io.IOException;
public class BigQuerySample {
public static void main(String[] args) throws IOException {
HttpTransport transport = GoogleTransport.create();
transport.addParser(new JsonCParser());
try {
// authenticate with ClientLogin
ClientLogin authenticator = new ClientLogin();
authenticator.authTokenType = "ndev";
authenticator.username = "*********@gmail.com";
authenticator.password = "**********";
authenticator.authenticate().setAuthorizationHeader(transport);
// make query request
HttpRequest request = transport.buildGetRequest();
request.setUrl("https://www.googleapis.com/bigquery/v1/query");
request.url.put("q","SELECT TOP(word, 50), COUNT(*) FROM publicdata:samples.shakespeare");
System.out.println(request.execute().parseAsString());
} catch (HttpResponseException e) {
System.err.println(e.response.parseAsString());
throw e;
}
}
}