我试图用java连接Google BigQuery,但得到了以下错误?
//错误-
找不到
线程“main”com中出现异常。谷歌。应用程序编程接口。客户http。HttpResponseException:找不到404
在com。谷歌。应用程序编程接口。客户http。HttpRequest。执行(HttpRequest.java:209)
在BigQuerySample。main(BigQuerySample.java:25)*/
//这是我的代码
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;
}
}
}
# 1 楼答案
Google BigQuery不支持ClientLogin身份验证。你从哪里得到的样本
# 2 楼答案
您正在查询一个不存在的URL。转到that URL返回“Not Found”,这是异常告诉您的。使用一个有效的URL,然后看看你的代码是否有效(你的代码可能完全没有问题)