最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

http status code 401 - accessing to my github repository from an apps script - Stack Overflow

programmeradmin1浏览0评论

was amazing to copy my files from google dive to github with an apps script. until yesterday, something is changed in the google-world.

This is just a try to verify the github token key:

function verifyGitHubToken2() {


  var token = 'GITHUB_TOKENold'; // Token di accesso GitHub
  var url = '/';
  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();

...but it leads to an error message:

Errore: Request failed for  returned code 401. Truncated server response: {"message":"Bad credentials","documentation_url":";,"status":"401"} (use muteHttpExceptions option to examine full response)

The token is correct and is working since I verified with a shell command:

C:\Users\Dash>curl -H "Authorization: token *****************************" 

I guess Google changed something! What could I try? Thanks a lot.


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 = '/' + userName + '/' + repoName + '/contents/'; // URL API per elencare i contenuti del repository
  var url = '/' + 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);
  }
}

I tried this code and leads to the message:

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

that means....An error occurred, try later! I Guess Google is driving me to use Google cloud storage instead of GitHub pages. that is very annoying

was amazing to copy my files from google dive to github with an apps script. until yesterday, something is changed in the google-world.

This is just a try to verify the github token key:

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

...but it leads to an error message:

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)

The token is correct and is working since I verified with a shell command:

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

I guess Google changed something! What could I try? Thanks a lot.


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);
  }
}

I tried this code and leads to the message:

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

that means....An error occurred, try later! I Guess Google is driving me to use Google cloud storage instead of GitHub pages. that is very annoying

Share Improve this question edited Jan 21 at 14:11 Davide Massi asked Jan 19 at 18:49 Davide MassiDavide Massi 213 bronze badges 6
  • 1 Try removing the trailing / at the end. – TheMaster Commented Jan 19 at 21:35
  • no, the error remains. - I'm reading news about googles changes in these hours, I wonder if it can affect my little work too: “Machine-generated traffic (also called automated traffic) refers to the practice of sending automated queries to Google. This includes scraping results for rank-checking purposes or other types of automated access to Google Search conducted without express permission. Machine-generated traffic consumes resources and interferes with our ability to best serve users. Such activities violate our spam policies and the Google Terms of Service.” – Davide Massi Commented Jan 19 at 22:45
  • Have you tried a new token? – TheMaster Commented Jan 19 at 23:39
  • Yes, I created new ones. Maybe deleting them all and creating a new one would make a difference? – Davide Massi Commented Jan 20 at 16:02
  • The code is working but maybe the credential token is expired or deleted I do suggest creating new Token it may help to solve the issue since I tried the code with a wrong token resulting with the code 401 response. – Lime Husky Commented Jan 20 at 16:04
 |  Show 1 more comment

1 Answer 1

Reset to default 0

SOLVED: the system can't haldle the token as a variable outside the code

发布评论

评论列表(0)

  1. 暂无评论