You need to have a GitHub account. Create a new token by following these steps:
Go to your GitHub settings.
Click on “Developer settings”.
Click on “Personal access tokens”.
Click on “Generate new token”.
Select the scopes you want the token to have (in this case, make sure to select the “notifications” scope).
Click on “Generate token”.
Copy the generated token and paste it into the Authorization header in the code above.
Create a spreadsheet file, open a new script from Extensions then Apps Script.
Rename both the spreadsheet and the new script with the same name, for example, github_account.
Add this source code into the editor and run the script.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | // the token works only for notifications function parseNotifications(data) { try { const notifications = JSON.parse(data); // access the parsed data console.log(notifications[0].subject.title); } catch (error) { console.log('Error parsing JSON:', error); } } function getGitHubNotifications() { var apiUrl = 'https://api.github.com/notifications'; var headers = { 'Authorization': 'Bearer YOUR_GITHUB_ACCESS_TOKEN', 'User-Agent': 'get-github-notifications-script' }; var options = { 'headers': headers }; var response = UrlFetchApp.fetch(apiUrl, options); var data = response.getContentText(); parseNotifications(data); } |
The result will be shown in the Execution log area.