Skip to content

Commit

Permalink
🧹 Deprecated x-instagram-ajax from the *Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskyfung committed Feb 14, 2023
1 parent 134e524 commit 884b4fc
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 138 deletions.
26 changes: 16 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@ A Google Apps Script to automatically fetch the latest available IG Stories of a
[![clasp](https://img.shields.io/badge/built%20with-clasp-4285f4.svg)](https://github.com/google/clasp) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) ![GitHub](https://img.shields.io/github/license/chriskyfung/AutoFetcher-IG-Stories-to-GDrive)
![Service Status](https://drive.google.com/u/0/uc?id=1BCyF1y8m1LKj8Um77st-3KC5-sTESoUZ&export=download) ![Last Tested Date](https://drive.google.com/u/0/uc?id=1VnSH5wtVOJXd_kmZsCSd3yQSpXTjMr0E&export=download)

🚧 **NEW RELEASE ON 2022-09-04** 🚧
🆕 NEW RELEASE ON 2023-02-14 🆕

Fixed the bug that caused ([duplicated log entries](https://github.com/chriskyfung/AutoFetcher-IG-Stories-to-GDrive/issues/53)).
🧹 **Deprecated `x-instagram-ajax` from the *Settings***.

Please update the Library Version to the latest in your Google Script or make a new copy of the Google Sheet template named with V5.

🚧 **IMPORTANT UPDATE ON 2022-08-23** 🚧

The previous builds no longer work from Aug 16,2022 due to Instagram code changes. An **ASBD identifier** and a **CSRF token** are now required for authentication to access the Instagram endpoint. Please update to Build 2022.08.23, and make a copy of the new Google Sheet.
Please update the Library Version to the latest in your Google Script or make a new copy of the [Google Sheet template named with V7](https://docs.google.com/spreadsheets/d/1td-CfE5NWHtKSeAMo32rPYQOZC5ydX9BXnXtumzYnL8/copy).

## How to Use

Expand All @@ -22,7 +18,7 @@ Starting from Build 2021.11.10, the Apps Script has been redesigned to work with
Make a copy of our Google Sheet template to your Google Drive by clicking the button below.

<div style="padding-left: 1.5em">
<a href="https://docs.google.com/spreadsheets/d/1jdbrn0okirXaMbbrm7Gj0N3LEsH-Fp6bzgAn3N72w5Y/copy">
<a href="https://docs.google.com/spreadsheets/d/1td-CfE5NWHtKSeAMo32rPYQOZC5ydX9BXnXtumzYnL8/copy">
<img src="https://img.shields.io/badge/Google%20Sheet-34a853?logo=googlesheets&logoColor=white" height="28" alt="">
</a>
</div>
Expand Down Expand Up @@ -67,8 +63,8 @@ Instagram
- x-ig-www-claim
: The value of `x-ig-www-claim` request-header field sends when you browse `www.instagram.com` with logging in to an account.

- x-instagram-ajax 🆕🆕
: The value of `x-instagram-ajax` request-header field sends when you browse `www.instagram.com` with logging in to an account.
- x-instagram-ajax
: This field has been deprecated from Build 2023.02.14 (= Library v7).

- cookie
: The value of `cookie` request-header field sends when you browse `www.instagram.com` with logging in to an account.
Expand Down Expand Up @@ -192,6 +188,16 @@ Now you can test your web app deployment by passing a URL with query strings lik

## History

🚧 **NEW RELEASE ON 2022-09-04** 🚧

Fixed the bug that caused ([duplicated log entries](https://github.com/chriskyfung/AutoFetcher-IG-Stories-to-GDrive/issues/53)).

Please update the Library Version to the latest in your Google Script or make a new copy of the Google Sheet template named with V5.

🚧 **IMPORTANT UPDATE ON 2022-08-23** 🚧

The previous builds no longer work from Aug 16,2022 due to Instagram code changes. An **ASBD identifier** and a **CSRF token** are now required for authentication to access the Instagram endpoint. Please update to Build 2022.08.23, and make a copy of the new Google Sheet.

**NEW FEATURES RELEASED ON 2021-12-06**

- Save the filename of downloaded files in Column E on log sheet page.
Expand Down
214 changes: 106 additions & 108 deletions dist/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* Homepage: https://chriskyfung.github.io/AutoFetcher-IG-Stories-to-GDrive/
*
* Build at: Tue, 22 Nov 2022 15:52:00 GMT
* Build at: Tue, 14 Feb 2023 15:01:52 GMT
*/

const IGSF = Object.create(null);
Expand All @@ -19,7 +19,7 @@ const IGSF = Object.create(null);

/**
* init.js
* Copyright (c) 2021
* Copyright (c) 2021-2023
*
* This file contains the Google Apps Script to initialize the Instagram
* stories fetcher, including the functions to load settings from the bounded
Expand All @@ -28,7 +28,7 @@ const IGSF = Object.create(null);
* @author Chris K.Y. Fung <github.com/chriskyfung>
*
* Created at : 2021-11-01
* Last updated at : 2022-08-23
* Last updated at : 2023-02-14
*/

/**
Expand Down Expand Up @@ -61,7 +61,6 @@ const igParams = {
X_CSRFTOKEN: null,
X_IG_APP_ID: null,
X_IG_WWW_CLAIM: null,
X_INSTAGRAM_AJAX: null,
COOKIE: null,
};
// User Perferences
Expand Down Expand Up @@ -123,12 +122,6 @@ function loadSettings() {
if (igParams.X_IG_WWW_CLAIM == '') {
throw new Error('Missing x-ig-www-claim in the Settings');
}
igParams.X_INSTAGRAM_AJAX = settingsSheet
.getRange('X_INSTAGRAM_AJAX')
.getDisplayValue();
if (igParams.X_INSTAGRAM_AJAX == '') {
throw new Error('Missing x-instagram-ajax in the Settings');
}
igParams.COOKIE = settingsSheet.getRange('COOKIE').getDisplayValue();
if (igParams.COOKIE == '') {
throw new Error('Missing cookie in the Settings');
Expand Down Expand Up @@ -255,98 +248,6 @@ function deleteSelected() {
}
}

/**
* badge.js
* Copyright (c) 2020-2021
*
* This file contains the code to create and update SVG badges,
* such as "last-tested-date.svg" and a "last-tested-status.svg".
*
* @author Chris K.Y. Fung <github.com/chriskyfung>
*
* Created at : 2020-10-08
* Last modified : 2021-11-02
*/

/**
* Create badges, namely "last-tested-date.svg" and a "last-tested-status.svg",
* in the destination folder of your Google Drive using DriveApp service.
* Obtain the file IDs and store them in the "Settings" page of the bounded
* Google Sheet file.
*/
function createBadages() {
loadSettings();
// Get the sheet stored the settings of Instagram Stories Fetcher
const spreadsheet = SpreadsheetApp.getActive();
const settingsSheet = spreadsheet.getSheetByName(sheetNames['settings']);
// Create blank SVG files in the destination folder, and store their file IDs
// in the global variable `badgeFileIds`.
badgeFileIds.lastTestedDate = dest.folderObj
.createFile('last-tested-date.svg', '', 'image/svg+xml')
.getId();
badgeFileIds.lastTestedStatus = dest.folderObj
.createFile('last-tested-status.svg', '', 'image/svg+xml')
.getId();
// Fill in the file IDs to the Google Sheet.
settingsSheet.getRange('dateBadgeId').setValue(badgeFileIds.lastTestedDate);
settingsSheet
.getRange('statusBadgeId')
.setValue(badgeFileIds.lastTestedStatus);
// Fill the blank SVG files with default contents.
setTestDateBadge();
setHealthStatusBadge();
}

/**
* Update the "last-tested-date.svg" file using DriveApp service.
* @return {string|null} The URL that can be used to download the file.
* Otherwise, returns null.
*/
function setTestDateBadge() {
if (badgeFileIds.lastTestedDate != '') {
const formattedDate = Utilities.formatDate(
new Date(),
'GMT',
'MMM dd, YYYY'
);
const file = DriveApp.getFileById(badgeFileIds.lastTestedDate);
return DriveApp.getFileByIdAndResourceKey(
badgeFileIds.lastTestedDate,
file.getResourceKey()
)
.setContent(
`<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="152" height="20" role="img" aria-label="last health check on ${formattedDate}"><title>tested on: ${formattedDate}</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="152" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="67" height="20" fill="#555"/><rect x="67" width="85" height="20" fill="#fe7d37"/><rect width="152" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="345" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="570">tested on</text><text x="345" y="140" transform="scale(.1)" fill="#fff" textLength="570">tested on</text><text aria-hidden="true" x="1085" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="750">${formattedDate}</text><text x="1085" y="140" transform="scale(.1)" fill="#fff" textLength="750">${formattedDate}</text></g></svg>`
)
.getDownloadUrl();
}
return null;
}

/**
* Update the "last-tested-status.svg" file using DriveApp service.
* @param {boolean} healthy The arguement to determine the badge color and the
* text to display in the badge. Default value is 'failed'.
* @return {string|null} The URL that can be used to download the file.
* Otherwise, returns null.
*/
function setHealthStatusBadge(healthy) {
if (badgeFileIds.lastTestedStatus != '') {
const [color, status] =
healthy === true ? ['#4c1', 'passed'] : ['#f00', 'failed'];
const file = DriveApp.getFileById(badgeFileIds.lastTestedStatus);
return DriveApp.getFileByIdAndResourceKey(
badgeFileIds.lastTestedStatus,
file.getResourceKey()
)
.setContent(
`<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="124" height="20" role="img" aria-label="health check: ${status}}"><title>health check: ${status}</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="124" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="75" height="20" fill="#555"/><rect x="75" width="49" height="20" fill="${color}"/><rect width="124" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="385" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="650">health check</text><text x="385" y="140" transform="scale(.1)" fill="#fff" textLength="650">health check</text><text aria-hidden="true" x="985" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="390">${status}</text><text x="985" y="140" transform="scale(.1)" fill="#fff" textLength="390">${status}</text></g></svg>`
)
.setDescription(`test-${healthy}`)
.getDownloadUrl();
}
return null;
}

// url_to_drive.gs
// Google Apps Script
// Allows uploading a URL directly to Google Drive.
Expand Down Expand Up @@ -448,7 +349,7 @@ function uploadToDrive(url, folderid, filename) {

/**
* fetcher.js
* Copyright (c) 2018-2021
* Copyright (c) 2018-2023
*
* This file contains the Google Apps Script to fetch and upload the media
* files from the latest available Stories of a Instagram user to your Google
Expand All @@ -457,7 +358,7 @@ function uploadToDrive(url, folderid, filename) {
* @author Chris K.Y. Fung <github.com/chriskyfung>
*
* Created at : 2018-01-29
* Last modified : 2022-11-22
* Last modified : 2023-02-14
*/

/**
Expand All @@ -480,20 +381,25 @@ function getInstagramData(query) {
accept: '*/*',
'accept-language': `zh-HK,zh-TW;q=0.9,zh;q=0.8,en;q=0.7,en-HK;q=0.6,ja-JP;q=0.5,ja;q=0.4,en-US;q=0.3`,
'cache-control': 'no-cache',
cookie: igParams.COOKIE,
dnt: 1,
pragma: 'no-cache',
'sec-ch--prefers-color-scheme': 'light',
'sec-ch-ua':
'"Chromium";v="104", " Not A;Brand";v="99", "Google Chrome";v="104"',
'"Not_A Brand";v="99", "Google Chrome";v="109", "Chromium";v="109"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-site',
'sec-fetch-site': 'same-origin',
'user-agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36',
'viewport-width': '960',
'x-asbd-id': igParams.X_ASBD_ID,
'x-csrftoken': igParams.X_CSRFTOKEN,
'x-ig-app-id': igParams.X_IG_APP_ID,
'x-ig-www-claim': igParams.X_IG_WWW_CLAIM,
'x-instagram-ajax': igParams.X_INSTAGRAM_AJAX,
cookie: igParams.COOKIE,
'x-requested-with': 'XMLHttpRequest',
},
referrer: 'https://www.instagram.com/',
referrerPolicy: 'strict-origin-when-cross-origin',
Expand Down Expand Up @@ -745,6 +651,98 @@ function batchFetch() {
});
}

/**
* badge.js
* Copyright (c) 2020-2021
*
* This file contains the code to create and update SVG badges,
* such as "last-tested-date.svg" and a "last-tested-status.svg".
*
* @author Chris K.Y. Fung <github.com/chriskyfung>
*
* Created at : 2020-10-08
* Last modified : 2021-11-02
*/

/**
* Create badges, namely "last-tested-date.svg" and a "last-tested-status.svg",
* in the destination folder of your Google Drive using DriveApp service.
* Obtain the file IDs and store them in the "Settings" page of the bounded
* Google Sheet file.
*/
function createBadages() {
loadSettings();
// Get the sheet stored the settings of Instagram Stories Fetcher
const spreadsheet = SpreadsheetApp.getActive();
const settingsSheet = spreadsheet.getSheetByName(sheetNames['settings']);
// Create blank SVG files in the destination folder, and store their file IDs
// in the global variable `badgeFileIds`.
badgeFileIds.lastTestedDate = dest.folderObj
.createFile('last-tested-date.svg', '', 'image/svg+xml')
.getId();
badgeFileIds.lastTestedStatus = dest.folderObj
.createFile('last-tested-status.svg', '', 'image/svg+xml')
.getId();
// Fill in the file IDs to the Google Sheet.
settingsSheet.getRange('dateBadgeId').setValue(badgeFileIds.lastTestedDate);
settingsSheet
.getRange('statusBadgeId')
.setValue(badgeFileIds.lastTestedStatus);
// Fill the blank SVG files with default contents.
setTestDateBadge();
setHealthStatusBadge();
}

/**
* Update the "last-tested-date.svg" file using DriveApp service.
* @return {string|null} The URL that can be used to download the file.
* Otherwise, returns null.
*/
function setTestDateBadge() {
if (badgeFileIds.lastTestedDate != '') {
const formattedDate = Utilities.formatDate(
new Date(),
'GMT',
'MMM dd, YYYY'
);
const file = DriveApp.getFileById(badgeFileIds.lastTestedDate);
return DriveApp.getFileByIdAndResourceKey(
badgeFileIds.lastTestedDate,
file.getResourceKey()
)
.setContent(
`<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="152" height="20" role="img" aria-label="last health check on ${formattedDate}"><title>tested on: ${formattedDate}</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="152" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="67" height="20" fill="#555"/><rect x="67" width="85" height="20" fill="#fe7d37"/><rect width="152" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="345" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="570">tested on</text><text x="345" y="140" transform="scale(.1)" fill="#fff" textLength="570">tested on</text><text aria-hidden="true" x="1085" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="750">${formattedDate}</text><text x="1085" y="140" transform="scale(.1)" fill="#fff" textLength="750">${formattedDate}</text></g></svg>`
)
.getDownloadUrl();
}
return null;
}

/**
* Update the "last-tested-status.svg" file using DriveApp service.
* @param {boolean} healthy The arguement to determine the badge color and the
* text to display in the badge. Default value is 'failed'.
* @return {string|null} The URL that can be used to download the file.
* Otherwise, returns null.
*/
function setHealthStatusBadge(healthy) {
if (badgeFileIds.lastTestedStatus != '') {
const [color, status] =
healthy === true ? ['#4c1', 'passed'] : ['#f00', 'failed'];
const file = DriveApp.getFileById(badgeFileIds.lastTestedStatus);
return DriveApp.getFileByIdAndResourceKey(
badgeFileIds.lastTestedStatus,
file.getResourceKey()
)
.setContent(
`<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="124" height="20" role="img" aria-label="health check: ${status}}"><title>health check: ${status}</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="124" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="75" height="20" fill="#555"/><rect x="75" width="49" height="20" fill="${color}"/><rect width="124" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="385" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="650">health check</text><text x="385" y="140" transform="scale(.1)" fill="#fff" textLength="650">health check</text><text aria-hidden="true" x="985" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="390">${status}</text><text x="985" y="140" transform="scale(.1)" fill="#fff" textLength="390">${status}</text></g></svg>`
)
.setDescription(`test-${healthy}`)
.getDownloadUrl();
}
return null;
}

/**
* Copyright (c) 2021-2022
*
Expand Down
8 changes: 4 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Starting from Build 2021.11.10, the Apps Script has been redesigned to work with
Make a copy of our Google Sheet template to your Google Drive by clicking the button below.

<div style="padding-left:1.5em;margin-bottom:1.5em">
<a href="https://docs.google.com/spreadsheets/d/1jdbrn0okirXaMbbrm7Gj0N3LEsH-Fp6bzgAn3N72w5Y/copy">
<a href="https://docs.google.com/spreadsheets/d/1td-CfE5NWHtKSeAMo32rPYQOZC5ydX9BXnXtumzYnL8/copy">
<amp-img src="https://img.shields.io/badge/Google%20Sheet-34a853?logo=googlesheets&logoColor=white" width="288" height="56" layout="fixed" alt=""></amp-img>
</a>
</div>
Expand Down Expand Up @@ -88,8 +88,8 @@ You can use the Google Sheet file and bound our script to it in the following wa
- x-ig-www-claim
: The value of `x-ig-www-claim` request-header field sends when you browse `www.instagram.com` with logging in to an account.

- x-instagram-ajax 🆕🆕
: The value of `x-instagram-ajax` request-header field sends when you browse `www.instagram.com` with logging in to an account.
- x-instagram-ajax
: This field has been deprecated from Build 2023.02.14 (= Library v7).

- cookie
: The value of `cookie` request-header field sends when you browse `www.instagram.com` with logging in to an account.
Expand Down Expand Up @@ -277,7 +277,7 @@ The version Build 2020.05.14 failed on 2020-06-02 due to the suspension of the d
1. Receiving an error message <span>'Exception: Request failed for https://i.instagram.com returned code 400.'</span>{:style="color:red;"}

{:style="font-style:italic;"}
It happens when your account has not been logged in via the Instagram website for a long time. Instagram will suspend your access token to prevent your account from being hacked. You can fix this issue by logging in again on _instagram.com_ and verify your account.
It happens when your account has not been logged in via the Instagram website for a long time. Instagram will suspend your access token to prevent your account from being hacked. You can fix this issue by opening _instagram.com_ to re-login and verify your account using a web browser.

2. Receiving an error message <span>'Exception: Unexpected error while getting the method or property getFolderById on object DriveApp.'</span>{:style="color:red;"}

Expand Down
Loading

0 comments on commit 884b4fc

Please sign in to comment.