Spaces:
				
			
			
	
			
			
		Paused
		
	
	
	
			
			
	
	
	
	
		
		
		Paused
		
	| import requests | |
| ENDPOINT = "https://gql.tokopedia.com/graphql/productReviewList" | |
| def request_product_id(shop_domain, product_key): | |
| endpoint = "https://gql.tokopedia.com/graphql/PDPGetLayoutQuery" | |
| payload = { | |
| "operationName": "PDPGetLayoutQuery", | |
| "variables": { | |
| "shopDomain": f"{shop_domain}", | |
| "productKey": f"{product_key}", | |
| "apiVersion": 1, | |
| }, | |
| "query": """fragment ProductVariant on pdpDataProductVariant { | |
| errorCode | |
| parentID | |
| defaultChild | |
| children { | |
| productID | |
| } | |
| __typename | |
| } | |
| query PDPGetLayoutQuery($shopDomain: String, $productKey: String, $layoutID: String, $apiVersion: Float, $userLocation: pdpUserLocation, $extParam: String, $tokonow: pdpTokoNow, $deviceID: String) { | |
| pdpGetLayout(shopDomain: $shopDomain, productKey: $productKey, layoutID: $layoutID, apiVersion: $apiVersion, userLocation: $userLocation, extParam: $extParam, tokonow: $tokonow, deviceID: $deviceID) { | |
| requestID | |
| name | |
| pdpSession | |
| basicInfo { | |
| id: productID | |
| } | |
| components { | |
| name | |
| type | |
| position | |
| data { | |
| ...ProductVariant | |
| __typename | |
| } | |
| __typename | |
| } | |
| __typename | |
| } | |
| } | |
| """, | |
| } | |
| headers = { | |
| "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36", | |
| "Referer": "https://www.tokopedia.com", | |
| "X-TKPD-AKAMAI": "pdpGetLayout", | |
| } | |
| return requests.request(method="POST", url=endpoint, json=payload, headers=headers) | |
| def request_product_review(product_id, page=1, limit=20): | |
| payload = { | |
| "operationName": "productReviewList", | |
| "variables": { | |
| "productID": f"{product_id}", | |
| "page": page, | |
| "limit": limit, | |
| "sortBy": "", | |
| "filterBy": "", | |
| }, | |
| "query": """query productReviewList($productID: String!, $page: Int!, $limit: Int!, $sortBy: String, $filterBy: String) { | |
| productrevGetProductReviewList(productID: $productID, page: $page, limit: $limit, sortBy: $sortBy, filterBy: $filterBy) { | |
| productID | |
| list { | |
| id: feedbackID | |
| variantName | |
| message | |
| productRating | |
| reviewCreateTime | |
| reviewCreateTimestamp | |
| isReportable | |
| isAnonymous | |
| reviewResponse { | |
| message | |
| createTime | |
| __typename | |
| } | |
| user { | |
| userID | |
| fullName | |
| image | |
| url | |
| __typename | |
| } | |
| likeDislike { | |
| totalLike | |
| likeStatus | |
| __typename | |
| } | |
| stats { | |
| key | |
| formatted | |
| count | |
| __typename | |
| } | |
| badRatingReasonFmt | |
| __typename | |
| } | |
| shop { | |
| shopID | |
| name | |
| url | |
| image | |
| __typename | |
| } | |
| hasNext | |
| totalReviews | |
| __typename | |
| } | |
| } | |
| """, | |
| } | |
| headers = { | |
| "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36", | |
| "Referer": "https://www.tokopedia.com", | |
| "X-TKPD-AKAMAI": "productReviewList", | |
| } | |
| return requests.request(method="POST", url=ENDPOINT, json=payload, headers=headers) | 
