API индексации Google: в доступе отказано. Не удалось подтвердить владение URL - PullRequest
1 голос
/ 30 апреля 2020

Я просмотрел все другие темы по этому вопросу, и, к сожалению, они до сих пор не решили мою проблему, поэтому я надеюсь, что вы можете помочь! Я пытаюсь использовать Google Indexing API через Google App Script. До сих пор я:

Следовал документации шаг за шагом; создал учетную запись службы, подключил сценарий моего приложения к моему проекту G C и добавил адрес электронной почты моего клиента в качестве владельца свойства консоли поиска.

Я также включил в свой файл манифеста сценария приложения следующие oauthScopes:

    "oauthScopes": [
    "https://www.googleapis.com/auth/indexing",
    "https://www.googleapis.com/auth/script.external_request",
    "https://www.googleapis.com/auth/userinfo.email"
  ]

Большинство из 403 ошибок, о которых я читал, устраняются путем добавления клиентской электронной почты в виде владелец поисковой консоли, но в моем случае это не решило проблему. Рады предоставить более подробную информацию, если это необходимо! :)

Вот мой скрипт Google App:

var Json = {
    "private_key": "###",
    "client_email": "###",
    "client_id": "###",
    "user_email": "###"
};


/**
 * Authorizes and makes a request to the Google+ API.
 */
function run() {

  var requestBody = {
       "url":"http://testymctestface.com",
       "type":"URL_UPDATED"
}

   var options = {
        'method': 'POST',
        'contentType': 'application/json',
        'headers': {
            'Authorization': 'Bearer ' + ScriptApp.getOAuthToken()
        },
        'payload': JSON.stringify(requestBody),
        'muteHttpExceptions': true
    };

        var service = getService();
        var url = 'https://indexing.googleapis.com/v3/urlNotifications:publish';
        var response = UrlFetchApp.fetch(url,options);
        Logger.log(response);

}

/**
 * Reset the authorization state, so that it can be re-tested.
 */
function reset() {

  var service = getService();
  service.reset();
}

/**
 * Configures the service.
 */
function getService() {
  return OAuth2.createService('Indexing API')
      // Set the endpoint URLs.
      .setAuthorizationBaseUrl('https://accounts.google.com/o/oauth2/auth')
      .setTokenUrl('https://accounts.google.com/o/oauth2/token')

      // Set the client ID and secret.
      .setPrivateKey(Json.private_key)
      .setIssuer(Json.client_email)
      .setSubject(Json.user_email)
      .setClientId(Json.client_id)

      // Set the name of the callback function that should be invoked to complete
      // the OAuth flow.
      .setCallbackFunction('authCallback')

      // Set the property store where authorized tokens should be persisted.
      .setPropertyStore(PropertiesService.getUserProperties())

      // Set the scope and additional Google-specific parameters.
      .setScope('https://www.googleapis.com/auth/indexing')
      .setParam('access_type', 'offline')
      .setParam('approval_prompt', 'force')
      .setParam('login_hint', Session.getActiveUser().getEmail());
}

/**
 * Handles the OAuth callback.
 */
function authCallback(request) {
  var service = getService();
  var authorized = service.handleCallback(request);
  if (authorized) {
    return HtmlService.createHtmlOutput('Success!');
  } else {
    return HtmlService.createHtmlOutput('Denied');
  }
}
...