Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- base: https://id.pinterest.com/
- note : gak tau token nya apakah bakalan bertahan lama / kagak. tapi kata orang" sih bertahan lama :v
- pint skrep by wolep
- param: string pint url (sup vid and image)
- throw error, jadi selalu pakai catch, handle error sesuka hati.. mungkin bs 500 atau friendly outout
- skrep api ori pint
- output konsisten sudah saya serialize :v
- liat penggunaan di bawah ya
- 24 januari 2026
- */
- const pinterest = {
- getData: async function (pinterestUrl) {
- const pinterestId = await this.getPinterestIdFromUrl(pinterestUrl)
- const res = await fetch("https://id.pinterest.com/_/graphql/", {
- "headers": {
- "accept-encoding": "gzip, deflate, br, zstd",
- "content-type": "application/json",
- "cookie": "csrftoken=f199c374cd68fda2595b9cc9bb9c7d5d;}",
- "x-csrftoken": "f199c374cd68fda2595b9cc9bb9c7d5d",
- },
- "body": JSON.stringify({
- "queryHash": "91dc7817f1acf1c2fb8d505d1c79dedebcb3baa1794065ba3602b843099f8ff7",
- "variables": {
- "pinId": pinterestId,
- "isAuth": false,
- "isDesktop": true,
- "shouldPrefetchStoryPinFragment": false,
- "isUnauth": true
- }
- }),
- "method": "POST",
- })
- if (!res.ok) throw Error(`${res.status} ${res.statusText} on ${res.url}`)
- const json = await res.json()
- return this.serialize(json)
- },
- serialize: function (pinterestResponse) {
- //return pinterestResponse
- // path shorter
- const data = pinterestResponse.data.v3GetPinQuery.data
- // post
- const post = {
- title: data?.unauthOnPageTitle?.trim() || '(no title)',
- description: data?.description.trim(),
- likesCount: data?.totalReactionCount || 0,
- shareCount: data?.shareCount || 0,
- commentCount: data?.aggregatedPinData.commentCount || 0,
- createdAt: data?.createdAt || '(unknown)'
- }
- // user
- const user = {
- fullName: data?.originPinner?.fullName || '(unknown)',
- username: data?.originPinner?.username || '(unknown)'
- }
- const v = data?.storyPinData?.pages[0]?.blocks[0]?.videoDataV2?.videoList720P?.v720P ||
- data?.videos?.videoList?.v720P
- const content = {
- images: Object.keys(data).filter(k => k.startsWith('images_')).map(k => ({ ...data[k], name: k.replace('images_', '') })),
- videos: v ? [v] : []
- }
- return {
- user,
- post,
- content
- }
- },
- getPinterestIdFromUrl: async function (pinterestUrl) {
- const shortUrl = /pin\.it/i.test(pinterestUrl)
- let utext
- if (shortUrl) {
- const r = await fetch(pinterestUrl, { method: 'head', redirect: 'follow', })
- utext = r.url
- } else {
- const validHostname = /pinterest/i.test(pinterestUrl)
- if (!validHostname) throw Error(`${pinterestUrl} invalid. hostname invalid`)
- utext = pinterestUrl
- }
- const url = new URL(utext)
- const pinId = url.pathname.match(/\/pin\/(\d+)/)?.[1]
- if (!pinId) throw Error(`${pinterestUrl} invalid. cant parse pinterest id`)
- return pinId
- }
- }
- // export esm, cjs ya anuin sendiri :v
- export { pinterest }
- // cara pakai
- // pinterest.getData('https://id.pinterest.com/pin/10414642883372969/')
- // .then(r => console.log(JSON.stringify(r, null, 2)))
- // .catch(console.log)
- /* output
- {
- "user": {
- "fullName": "HanVibey_",
- "username": "animetim_e"
- },
- "post": {
- "title": "Angry Anime Face",
- "description": "",
- "likesCount": 270,
- "shareCount": 104,
- "commentCount": 3,
- "createdAt": "Wed, 31 Dec 2025 07:32:39 +0000"
- },
- "content": {
- "images": [
- {
- "height": 419,
- "width": 236,
- "url": "https://i.pinimg.com/236x/29/f6/4c/29f64c75d6f77eaa44e2720a82b5b999.jpg",
- "name": "236x"
- },
- {
- "height": 136,
- "width": 136,
- "url": "https://i.pinimg.com/136x136/29/f6/4c/29f64c75d6f77eaa44e2720a82b5b999.jpg",
- "name": "136x136"
- },
- {
- "url": "https://i.pinimg.com/60x60/29/f6/4c/29f64c75d6f77eaa44e2720a82b5b999.jpg",
- "name": "60x60"
- },
- {
- "url": "https://i.pinimg.com/236x/29/f6/4c/29f64c75d6f77eaa44e2720a82b5b999.jpg",
- "name": "170x"
- },
- {
- "url": "https://i.pinimg.com/474x/29/f6/4c/29f64c75d6f77eaa44e2720a82b5b999.jpg",
- "height": 842,
- "width": 474,
- "name": "474x"
- },
- {
- "url": "https://i.pinimg.com/564x/29/f6/4c/29f64c75d6f77eaa44e2720a82b5b999.jpg",
- "height": 1002,
- "width": 564,
- "name": "564x"
- },
- {
- "url": "https://i.pinimg.com/736x/29/f6/4c/29f64c75d6f77eaa44e2720a82b5b999.jpg",
- "height": 1280,
- "width": 720,
- "name": "736x"
- },
- {
- "url": "https://i.pinimg.com/600x315/29/f6/4c/29f64c75d6f77eaa44e2720a82b5b999.jpg",
- "name": "600x315"
- },
- {
- "url": "https://i.pinimg.com/originals/29/f6/4c/29f64c75d6f77eaa44e2720a82b5b999.jpg",
- "name": "orig"
- }
- ],
- "videos": [
- {
- "thumbnail": "https://i.pinimg.com/videos/thumbnails/originals/f9/8f/a6/f98fa6d0ec8108ac9b87dce3563b89f3.0000000.jpg",
- "url": "https://v1.pinimg.com/videos/iht/expMp4/f9/8f/a6/f98fa6d0ec8108ac9b87dce3563b89f3_720w.mp4",
- "width": 720,
- "height": 1280,
- "duration": 9933
- }
- ]
- }
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment