【问题标题】:JAVA: Google Real Time Indexing API 403 error - Indexing API has not been used in projectJAVA:Google Real Time Indexing API 403 错误 - 项目中未使用索引 API
【发布时间】:2017-03-16 23:01:50
【问题描述】:

我正在尝试为谷歌实时索引做一个帖子。我只是试图向谷歌发送一个空原子——我主要是在测试 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();

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

【问题讨论】:

    标签: java google-realtime-api


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2019-06-09
      • 1970-01-01
      • 1970-01-01
      • 2018-08-14
      • 1970-01-01
      • 1970-01-01
      • 2015-01-15
      • 2020-04-10
      • 2019-04-07
      相关资源
      最近更新 更多