JAVA:Google Real Time Indexing API 403错误 - 索引API尚未在项目中使用

时间:2017-03-16 23:01:50

标签: java google-realtime-api

我试图为Google实时索引编写帖子。我只是试图向谷歌发送一个空原子 - 我主要测试外壳上的放大器是什么样的。我的空原子帖后面出现以下错误:

"error": {
    "code": 403,
    "message": "Google Indexing API has not been used in project api-project-xxx before or it is disabled. 
Enable it by visiting https://console.developers.google.com/apis/api/indexing.googleapis.com/overview?project=api-project-xxx  then retry. 
If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry."    
}

我按照上面的链接看到我没有权限查看那里的内容......我收到了一个.json api-project文件,我认为该文件可用作身份验证文件,我不确定问题是否使用" api-project.json"文件或其他东西。以下是产生上述错误的基本脚本:

String scopes = "https://www.googleapis.com/auth/indexing";
String endPoint = "https://indexing.googleapis.com/xxx...";
genericUrl = new GenericUrl(endPoint);

httpTransport = GoogleNetHttpTransport.newTrustedTransport();
requestFactory = httpTransport.createRequestFactory();
jsonFactory = new JacksonFactory();
InputStream in = IOUtils.toInputStream("api-project.json");

String atom = "< ... basic atom shell  is here .... >"  
request = requestFactory.buildPostRequest(genericUrl, ByteArrayContent.fromString(null, atom));
credentials = GoogleCredential.fromStream(in, httpTransport, jsonFactory).createScoped(Collections.singleton(scopes));
credentials.initialize(request);
HttpResponse response = request.execute();

这里的任何指导都将非常感谢。非常感谢。

1 个答案:

答案 0 :(得分:0)

上面的脚本很好 - 脚本之外几乎没有问题。第一个是我们的域名未设置为谷歌项目,第二个是我用作凭据的文件。一旦我得到了正确的文件,我得到了200回复​​。