0

我正在尝试为谷歌实时索引做一个帖子。我只是试图向谷歌发送一个空原子——我主要是在测试 shell 以了解未来的 amp 帖子。我的空原子帖子出现以下错误:

"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();

这里的任何指导将不胜感激。非常感谢。

4

1 回答 1

0

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

于 2017-03-17T16:35:57.113 回答