从应用程序脚本访问我的 github 存储库

问题描述 投票:0回答:1

使用应用程序脚本将我的文件从 google div 复制到 github 真是太棒了。直到昨天,谷歌世界发生了一些变化。

这只是尝试验证 github 令牌密钥:

function verifyGitHubToken2() {


  var token = 'GITHUB_TOKENold'; // Token di accesso GitHub
  var url = 'https://api.github.com/repos/polvere73/work/HTML/';
  var options = {
    "method": "get",
    "headers": {
      "Authorization": "token " + token
    }
  };

  try {
    var response = UrlFetchApp.fetch(url, options);
    Logger.log(response.getContentText());
  } catch (e) {
    Logger.log("Errore: " + e.message);
  }
}

// Esegui questa funzione per verificare il tuo token GitHub
verifyGitHubToken2();

...但这会导致错误消息:

Errore: Request failed for https://api.github.com returned code 401. Truncated server response: {"message":"Bad credentials","documentation_url":"https://docs.github.com/rest","status":"401"} (use muteHttpExceptions option to examine full response)

令牌是正确的,并且自从我使用 shell 命令验证以来一直在工作:

C:\Users\Dash>curl -H "Authorization: token *****************************" https://api.github.com/repos/polvere73/work/contents/HTML

我猜谷歌改变了一些东西! 我可以尝试什么?非常感谢。


function listRepoContents() {
  var userName = 'polvere73'; // Inserisci il tuo nome utente GitHub
  var repoName = 'work'; // Inserisci il nome del repository
  var token = 'GITHUB_TOKEN'; // Inserisci il tuo token di accesso personale
  //var url = 'https://api.github.com/repos/' + userName + '/' + repoName + '/contents/'; // URL API per elencare i contenuti del repository
  var url = 'https://api.github.com/repos/' + userName + '/' + repoName + '/contents/'; // URL API per elencare i contenuti del repository

  var options = {
    method: 'get',
    muteHttpExceptions: true,
    headers: {
      Authorization: 'token ' + token
    }
  };

  try {
    var response = UrlFetchApp.fetch(url, options);
    var data = JSON.parse(response.getContentText());

    if (response.getResponseCode() === 200) {
      Logger.log('File trovati nel repository:');
      data.forEach(function(file) {
        Logger.log(file.name);
      });
    } else {
      Logger.log('Errore: ' + data.message);
    }
  } catch (e) {
    Logger.log('Errore: ' + e.message);
  }
}

我尝试了这段代码并导致了消息:

Errore  Si è verificato un errore sconosciuto. Riprova più tardi

这意味着...发生错误,请稍后再试! 我猜 Google 正在促使我使用 Google 云存储而不是 GitHub 页面。这很烦人

google-apps-script http-status-code-401 github-token
1个回答
0
投票

enter image description here

已解决:系统无法将令牌作为代码外部的变量进行处理

© www.soinside.com 2019 - 2024. All rights reserved.