postComment({ mediaId, commentText }) {
        if (commentText.length > 300) {
            throw new Error("The total length of the comment cannot exceed 300 characters.");
        }

        if (/[a-z]/gi.test(commentText) && commentText === commentText.toUpperCase()) {
            throw new Error("The comment cannot consist of all capital letters.");
        }

        if (/#[^#]+\b/gu.exec(commentText).length > 4) {
            throw new Error("The comment cannot contain more than 4 hashtags.");
        }

        if (/\bhttps?:\/\/\S+\.\S+/g.exec(commentText).length > 1) {
            throw new Error("The comment cannot contain more than 1 URL.");
        }

        mediaId = this.sanitiseMediaId(mediaId);
        let options = Object.assign(this.defaultRequestOptions);
        options["url"] = `https://www.instagram.com/web/comments/${media_id}/add/`;
        options["headers"]["X-CSRFToken"] = this.csrfToken;
        options["form"] = { "comment_text": commentText }
        return this.fetchPage({ options, isPost: true });
    }
/**
     * Post a new comment. Login required.
     *
     * @param {*} { mediaId, commentText }
     * @returns "{
                    "created_time": 1483096000,
                    "text": "This is a comment",
                    "status": "ok",
                    "from": {
                        "username": "somebody",
                        "profile_picture": "..",
                        "id": "1234567890",
                        "full_name": "Somebody"
                    },
                    "id": "1785800000"
                }"
     * @memberof Fusia
     */
Post a new comment. Login required.
Post a new comment . Login required .
postComment({ mediaId, commentText }) {
        if (commentText.length > 300) {
            throw new Error("The total length of the comment cannot exceed 300 characters.");
        }
        if (/[a-z]/gi.test(commentText) && commentText === commentText.toUpperCase()) {
            throw new Error("The comment cannot consist of all capital letters.");
        }
        if (/#[^#]+\b/gu.exec(commentText).length > 4) {
            throw new Error("The comment cannot contain more than 4 hashtags.");
        }
        if (/\bhttps?:\/\/\S+\.\S+/g.exec(commentText).length > 1) {
            throw new Error("The comment cannot contain more than 1 URL.");
        }
        mediaId = this.sanitiseMediaId(mediaId);
        let options = Object.assign(this.defaultRequestOptions);
        options["url"] = `https://www.instagram.com/web/comments/${media_id}/add/`;
        options["headers"]["X-CSRFToken"] = this.csrfToken;
        options["form"] = { "comment_text": commentText }
        return this.fetchPage({ options, isPost: true });
    }
postComment ( { mediaId , commentText } ) { if ( commentText . length > 300 ) { throw new Error ( "The total length of the comment cannot exceed 300 characters." ) ; } if ( / [a-z] / gi . test ( commentText ) && commentText === commentText . toUpperCase ( ) ) { throw new Error ( "The comment cannot consist of all capital letters." ) ; } if ( / #[^#]+\b / gu . exec ( commentText ) . length > 4 ) { throw new Error ( "The comment cannot contain more than 4 hashtags." ) ; } if ( / \bhttps?:\/\/\S+\.\S+ / g . exec ( commentText ) . length > 1 ) { throw new Error ( "The comment cannot contain more than 1 URL." ) ; } mediaId = this . sanitiseMediaId ( mediaId ) ; let options = Object . assign ( this . defaultRequestOptions ) ; options [ "url" ] = ` ${ media_id } ` ; options [ "headers" ] [ "X-CSRFToken" ] = this . csrfToken ; options [ "form" ] = { "comment_text" : commentText } return this . fetchPage ( { options , isPost : true } ) ; }
Post a new comment.
Post a new comment .