From 884b4fc30251734749caffd6619df87b0250ec80 Mon Sep 17 00:00:00 2001
From: "Chris K.Y. FUNG" <8746768+chriskyfung@users.noreply.github.com>
Date: Tue, 14 Feb 2023 23:23:20 +0800
Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20Deprecated=20`x-instagram-ajax`?=
=?UTF-8?q?=20from=20the=20*Settings?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 26 +++---
dist/bundle.js | 214 ++++++++++++++++++++++++-------------------------
docs/index.md | 8 +-
package.json | 3 +-
src/fetcher.js | 17 ++--
src/init.js | 11 +--
6 files changed, 141 insertions(+), 138 deletions(-)
diff --git a/README.md b/README.md
index 7ffdf55..80d7636 100644
--- a/README.md
+++ b/README.md
@@ -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
@@ -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.
@@ -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.
@@ -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.
diff --git a/dist/bundle.js b/dist/bundle.js
index c266ca1..dde03f9 100644
--- a/dist/bundle.js
+++ b/dist/bundle.js
@@ -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);
@@ -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
@@ -28,7 +28,7 @@ const IGSF = Object.create(null);
* @author Chris K.Y. Fung
*
* Created at : 2021-11-01
- * Last updated at : 2022-08-23
+ * Last updated at : 2023-02-14
*/
/**
@@ -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
@@ -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');
@@ -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
- *
- * 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(
- ``
- )
- .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(
- ``
- )
- .setDescription(`test-${healthy}`)
- .getDownloadUrl();
- }
- return null;
-}
-
// url_to_drive.gs
// Google Apps Script
// Allows uploading a URL directly to Google Drive.
@@ -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
@@ -457,7 +358,7 @@ function uploadToDrive(url, folderid, filename) {
* @author Chris K.Y. Fung
*
* Created at : 2018-01-29
- * Last modified : 2022-11-22
+ * Last modified : 2023-02-14
*/
/**
@@ -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',
@@ -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
+ *
+ * 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(
+ ``
+ )
+ .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(
+ ``
+ )
+ .setDescription(`test-${healthy}`)
+ .getDownloadUrl();
+ }
+ return null;
+}
+
/**
* Copyright (c) 2021-2022
*
diff --git a/docs/index.md b/docs/index.md
index 8037a10..6f29e51 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -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.
@@ -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.
@@ -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 'Exception: Request failed for https://i.instagram.com returned code 400.'{: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 'Exception: Unexpected error while getting the method or property getFolderById on object DriveApp.'{:style="color:red;"}
diff --git a/package.json b/package.json
index fce63a7..85a1dd0 100644
--- a/package.json
+++ b/package.json
@@ -16,7 +16,8 @@
{
"type": "github",
"url": "https://github.com/sponsors/chriskyfung"
- }, {
+ },
+ {
"type": "buymeacoffee",
"url": "https://www.buymeacoffee.com/chrisfungky"
}
diff --git a/src/fetcher.js b/src/fetcher.js
index 9f279f8..cbff67a 100644
--- a/src/fetcher.js
+++ b/src/fetcher.js
@@ -1,6 +1,6 @@
/**
* 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
@@ -9,7 +9,7 @@
* @author Chris K.Y. Fung
*
* Created at : 2018-01-29
- * Last modified : 2022-11-22
+ * Last modified : 2023-02-14
*/
import {
@@ -42,20 +42,25 @@ export 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',
diff --git a/src/init.js b/src/init.js
index 3c27acd..d548ed0 100644
--- a/src/init.js
+++ b/src/init.js
@@ -1,6 +1,6 @@
/**
* 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
@@ -9,7 +9,7 @@
* @author Chris K.Y. Fung
*
* Created at : 2021-11-01
- * Last updated at : 2022-08-23
+ * Last updated at : 2023-02-14
*/
/**
@@ -42,7 +42,6 @@ export const igParams = {
X_CSRFTOKEN: null,
X_IG_APP_ID: null,
X_IG_WWW_CLAIM: null,
- X_INSTAGRAM_AJAX: null,
COOKIE: null,
};
// User Perferences
@@ -104,12 +103,6 @@ export 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');