TobyG74 / tiktok-api-dl

Scrapper for download Video, Image, Music from Tiktok
Apache License 2.0
69 stars 18 forks source link

Not Working on Vercel wIth Next.JS 403 Forbitten #6

Closed happer64bit closed 11 months ago

happer64bit commented 12 months ago

I am trying to build my own downloader. I got error when I sent request on production it doesn't happens on localhost.

You can see my app here: https://tiked.vercel.app

bol(errored)]: null,
    [Symbol(kHighWaterMark)]: 16384,
    [Symbol(kRejectNonStandardBodyWrites)]: false,
    [Symbol(kUniqueHeaders)]: null
  },
  response: {
    status: 403,
    statusText: 'Forbidden',
    headers: Object [AxiosHeaders] {
      server: 'nginx',
      'content-length': '0',
      'x-tt-system-error': '3',
      'proxy-status': '0000201403061000',
      'x-tt-trace-host': '01e11b73288eb114e390b13e0c7561618a4a1dba3aca6ecb8cc2669793af26e8d40bdb891b3e290b2ebc614e9db09a694a251d8f0225f1b2425979878fb12ff181f96bf1d85c9333078276aa27df7569a4',
      'x-tt-logid': '202309121400226B84A888AE8572102683',
      expires: 'Tue, 12 Sep 2023 14:00:22 GMT',
      'cache-control': 'max-age=0, no-cache, no-store',
      pragma: 'no-cache',
      date: 'Tue, 12 Sep 2023 14:00:22 GMT',
      'x-cache': 'TCP_MISS from a23-202-158-7.deploy.akamaitechnologies.com (AkamaiGHost/11.2.4-50766152) (-)',
      connection: 'close',
      'x-tt-trace-tag': 'id=16;cdn-cache=miss;type=dyn',
      'server-timing': 'cdn-cache; desc=MISS, edge; dur=1, origin; dur=7',
      'x-origin-response-time': '7,23.202.158.7',
      'x-akamai-request-id': 'a33467cc'
    },
    config: {
      transitional: [Object],
      adapter: 'http',
      transformRequest: [Array],
      transformResponse: [Array],
      timeout: 0,
      xsrfCookieName: 'XSRF-TOKEN',
      xsrfHeaderName: 'X-XSRF-TOKEN',
      maxContentLength: -1,
      maxBodyLength: -1,
      env: [Object],
      validateStatus: [Function: validateStatus],
      headers: [Object [AxiosHeaders]],
      method: 'head',
      url: 'https://www.tiktok.com/@yunsdespise/video/7226365854097706282?q=image%20slideshow&t=1694233131390',
      data: undefined
    },
    request: <ref *1> ClientRequest {
      _events: [Object: null prototype],
      _eventsCount: 7,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      destroyed: false,
      _last: true,
      chunkedEncoding: false,
      shouldKeepAlive: false,
      maxRequestsOnConnectionReached: false,
      _defaultKeepAlive: true,
      useChunkedEncodingByDefault: false,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      strictContentLength: false,
      _contentLength: 0,
      _hasBody: true,
      _trailer: '',
      finished: true,
      _headerSent: true,
      _closed: false,
      socket: [TLSSocket],
      _header: 'HEAD /@yunsdespise/video/7226365854097706282?q=image%20slideshow&t=1694233131390 HTTP/1.1\r\n' +
        'Accept: application/json, text/plain, */*\r\n' +
        'User-Agent: axios/1.5.0\r\n' +
        'Accept-Encoding: gzip, compress, deflate, br\r\n' +
        'x-vercel-id: sin1::ztbqx-1694527220519-699460779dbb\r\n' +
        'Host: www.tiktok.com\r\n' +
        'Connection: close\r\n' +
        '\r\n',
      _keepAliveTimeout: 0,
      _onPendingData: [Function: nop],
      agent: [Agent],
      socketPath: undefined,
      method: 'HEAD',
      maxHeaderSize: undefined,
      insecureHTTPParser: undefined,
      joinDuplicateHeaders: undefined,
      path: '/@yunsdespise/video/7226365854097706282?q=image%20slideshow&t=1694233131390',
      _ended: true,
      res: [IncomingMessage],
      aborted: false,
      timeoutCb: null,
      upgradeOrConnect: false,
      parser: null,
      maxHeadersCount: null,
      reusedSocket: false,
      host: 'www.tiktok.com',
      protocol: 'https:',
      _redirectable: [Writable],
      [Symbol(kCapture)]: false,
      [Symbol(kBytesWritten)]: 0,
      [Symbol(kNeedDrain)]: false,
      [Symbol(corked)]: 0,
      [Symbol(kOutHeaders)]: [Object: null prototype],
      [Symbol(errored)]: null,
      [Symbol(kHighWaterMark)]: 16384,
      [Symbol(kRejectNonStandardBodyWrites)]: false,
      [Symbol(kUniqueHeaders)]: null
    },
    data: ''
  }
}
AnderRedna commented 11 months ago

same error, did you find a solution?

farizrifqi commented 11 months ago

Perhaps it's a CORS problem. Happened to me few time since using private/unofficial API on NextJS.

Since this is a package and we are not able to change the request URL, then backend is kind a must. In my case I am using ExpressJS. Sadly I am not sure whether it can be deployed on serverless or not.

But if you're doing http request with your on URL, you can try cors-anywhere.

TobyG74 commented 11 months ago

I am trying to build my own downloader. I got error when I sent request on production it doesn't happens on localhost.

You can see my app here: https://tiked.vercel.app

bol(errored)]: null,
    [Symbol(kHighWaterMark)]: 16384,
    [Symbol(kRejectNonStandardBodyWrites)]: false,
    [Symbol(kUniqueHeaders)]: null
  },
  response: {
    status: 403,
    statusText: 'Forbidden',
    headers: Object [AxiosHeaders] {
      server: 'nginx',
      'content-length': '0',
      'x-tt-system-error': '3',
      'proxy-status': '0000201403061000',
      'x-tt-trace-host': '01e11b73288eb114e390b13e0c7561618a4a1dba3aca6ecb8cc2669793af26e8d40bdb891b3e290b2ebc614e9db09a694a251d8f0225f1b2425979878fb12ff181f96bf1d85c9333078276aa27df7569a4',
      'x-tt-logid': '202309121400226B84A888AE8572102683',
      expires: 'Tue, 12 Sep 2023 14:00:22 GMT',
      'cache-control': 'max-age=0, no-cache, no-store',
      pragma: 'no-cache',
      date: 'Tue, 12 Sep 2023 14:00:22 GMT',
      'x-cache': 'TCP_MISS from a23-202-158-7.deploy.akamaitechnologies.com (AkamaiGHost/11.2.4-50766152) (-)',
      connection: 'close',
      'x-tt-trace-tag': 'id=16;cdn-cache=miss;type=dyn',
      'server-timing': 'cdn-cache; desc=MISS, edge; dur=1, origin; dur=7',
      'x-origin-response-time': '7,23.202.158.7',
      'x-akamai-request-id': 'a33467cc'
    },
    config: {
      transitional: [Object],
      adapter: 'http',
      transformRequest: [Array],
      transformResponse: [Array],
      timeout: 0,
      xsrfCookieName: 'XSRF-TOKEN',
      xsrfHeaderName: 'X-XSRF-TOKEN',
      maxContentLength: -1,
      maxBodyLength: -1,
      env: [Object],
      validateStatus: [Function: validateStatus],
      headers: [Object [AxiosHeaders]],
      method: 'head',
      url: 'https://www.tiktok.com/@yunsdespise/video/7226365854097706282?q=image%20slideshow&t=1694233131390',
      data: undefined
    },
    request: <ref *1> ClientRequest {
      _events: [Object: null prototype],
      _eventsCount: 7,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      destroyed: false,
      _last: true,
      chunkedEncoding: false,
      shouldKeepAlive: false,
      maxRequestsOnConnectionReached: false,
      _defaultKeepAlive: true,
      useChunkedEncodingByDefault: false,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      strictContentLength: false,
      _contentLength: 0,
      _hasBody: true,
      _trailer: '',
      finished: true,
      _headerSent: true,
      _closed: false,
      socket: [TLSSocket],
      _header: 'HEAD /@yunsdespise/video/7226365854097706282?q=image%20slideshow&t=1694233131390 HTTP/1.1\r\n' +
        'Accept: application/json, text/plain, */*\r\n' +
        'User-Agent: axios/1.5.0\r\n' +
        'Accept-Encoding: gzip, compress, deflate, br\r\n' +
        'x-vercel-id: sin1::ztbqx-1694527220519-699460779dbb\r\n' +
        'Host: www.tiktok.com\r\n' +
        'Connection: close\r\n' +
        '\r\n',
      _keepAliveTimeout: 0,
      _onPendingData: [Function: nop],
      agent: [Agent],
      socketPath: undefined,
      method: 'HEAD',
      maxHeaderSize: undefined,
      insecureHTTPParser: undefined,
      joinDuplicateHeaders: undefined,
      path: '/@yunsdespise/video/7226365854097706282?q=image%20slideshow&t=1694233131390',
      _ended: true,
      res: [IncomingMessage],
      aborted: false,
      timeoutCb: null,
      upgradeOrConnect: false,
      parser: null,
      maxHeadersCount: null,
      reusedSocket: false,
      host: 'www.tiktok.com',
      protocol: 'https:',
      _redirectable: [Writable],
      [Symbol(kCapture)]: false,
      [Symbol(kBytesWritten)]: 0,
      [Symbol(kNeedDrain)]: false,
      [Symbol(corked)]: 0,
      [Symbol(kOutHeaders)]: [Object: null prototype],
      [Symbol(errored)]: null,
      [Symbol(kHighWaterMark)]: 16384,
      [Symbol(kRejectNonStandardBodyWrites)]: false,
      [Symbol(kUniqueHeaders)]: null
    },
    data: ''
  }
}

When I try to open your video URL, it also won't open. There may be differences, such as allowing video URLs to be accessed by only some countries.

![Uploading Screenshot_2023-10-03-10-56-51-660_com.kiwibrowser.browser.jpg…]()

happer64bit commented 11 months ago

@TobyG74 https://tiked.netlify.app/ here is my web