Using Swift

How to Scrape TikTok Shop Shop Products with Swift

Get TikTok Shop products from a profile using Swift. This comprehensive guide will walk you through the entire process, from setup to implementation.

Overview

What You'll Learn

  • Setting up your Swift environment
  • Installing the required HTTP client
  • Authenticating with SociaVault API
  • Making requests to TikTok Shop
  • Handling responses and errors

What You'll Get

  • Access to products data
  • JSON formatted responses
  • Real-time data access
  • Scalable solution
  • Error handling patterns

Prerequisites

1. API Key

First, you'll need a SociaVault API key to authenticate your requests.

2. Development Environment

Make sure you have the following installed:

  • Swift installed
  • A code editor (VS Code, Sublime, etc.)
  • Command line interface access

Implementation

Step 1: Install HTTP Client

We'll use URLSession to make HTTP requests.

bash
// Standard library

Step 2: API Implementation

Now let's make a request to the TikTok Shop API using Swift. Replace YOUR_API_KEY with your actual API key.

swift
import Foundation

let url = URL(string: "https://api.sociavault.com/tiktok-shop/products?url=https%3A%2F%2Fwww.tiktok.com%2F%40goli-nutrition")!
var request = URLRequest(url: url)
request.httpMethod = "GET"
request.addValue("YOUR_API_KEY", forHTTPHeaderField: "x-api-key")
request.addValue("application/json", forHTTPHeaderField: "Content-Type")

let task = URLSession.shared.dataTask(with: request) { data, response, error in
    if let data = data {
        if let json = try? JSONSerialization.jsonObject(with: data, options: []) {
            print(json)
        }
    }
}

task.resume()

Testing Your Code

API Parameters

ParameterTypeRequiredDescription
urlstringYesExample: https://www.tiktok.com/@goli-nutrition

Expected Response

You should receive a structured JSON response containing the products data.

json
{
  "success": true,
  "shopInfo": {
    "seller_id": "7495794203056835079",
    "sold_count": 3767605,
    "on_sell_product_count": 36,
    "review_count": 284185,
    "global_seller_id": "7495794203056835079",
    "global_sold_count": "3767605",
    "followers_count": "237879",
    "video_count": "2413",
    "enable_follow": true,
    "shop_name": "Goli Nutrition",
    "shop_logo": {
      "height": 300,
      "width": 300,
      "uri": "tos-useast5-i-omjb5zjo8w-tx/e7478d3e93d4487a9e772fa74e10f506",
      "url_list": [
        "https://p16-oec-general-useast5.ttcdn-us.com/tos-useast5-i-omjb5zjo8w-tx/e7478d3e93d4487a9e772fa74e10f506~tplv-fhlh96nyum-resize-webp:300:300.webp?dr=12185&from=2422056039&idc=useast8&ps=933b5bde&shcp=a6e80448&shp=905da467&t=555f072d"
      ]
    },
    "shop_rating": "4.6",
    "shop_link": "https://www.tiktok.com/shop/store/goli-nutrition/7495794203056835079",
    "format_sold_count": "3.7M",
    "region": "US",
    "display_on_sell_product_count": "36",
    "format_global_sold_count": "3.7M",
    "shop_slogan": "Health Simple✨\nVegan. Gluten-Free. Non-GMO.",
    "format_followers_count": "237.8K+",
    "format_video_count": "2413",
    "store_sub_score": [
      {
        "score": 0.9967,
        "type": 1,
        "score_percentage": "100",
        "high_light_tag": 1,
        "platform_rate_type": 1
      }
    ],
    "worst_rating": "0",
    "best_rating": "5",
    "creator_name": "Goli® Nutrition",
    "desc": "Shop Goli Nutrition on TikTok Shop! 3.7M sold, 237.8K+ followers. 89+% positive feedback. 50+% Ships in 48h, 100% replies in 24h. Join the trend!"
  },
  "products": [
    {
      "product_id": "1729527313880355335",
      "title": "Goli Ashwagandha & Vitamin D Gummy - Mixed Berry, KSM-66, Vegan, Plant Based, Non-GMO, Gluten-Free & Gelatin Free. America's #1 Ashwagandha Brand",
      "image": {
        "height": 1500,
        "width": 1500,
        "uri": "tos-useast5-i-omjb5zjo8w-tx/30fc1338a2bf474a9d252a790e4c119f",
        "url_list": [
          "https://p16-oec-general-useast5.ttcdn-us.com/tos-useast5-i-omjb5zjo8w-tx/30fc1338a2bf474a9d252a790e4c119f~tplv-fhlh96nyum-crop-webp:1500:1500.webp?dr=12190&from=2378011839&idc=useast8&ps=933b5bde&shcp=905da467&shp=8dbd94bf&t=555f072d"
        ]
      },
      "product_price_info": {
        "sku_id": "1729527298861535751",
        "symbol_position": 1,
        "show_currency_space": false,
        "currency_show_mode": 1,
        "currency_name": "USD",
        "currency_symbol": "$",
        "sale_price_decimal": "14.96",
        "origin_price_decimal": "24.99",
        "sale_price_format": "14.96",
        "origin_price_format": "24.99",
        "discount_format": "40%",
        "discount_decimal": "0.4",
        "reduce_price_format": "Saving $10.03",
        "single_product_price_format": "14.96",
        "single_product_price_decimal": "14.96",
        "sale_price_integer_part_format": "14",
        "sale_price_decimal_part_format": "96",
        "decimal_point_symbol": ".",
        "promotion_deduction_details": {
          "seller_subtotal_deduction": "10.03",
          "seller_subtotal_deduction_decimal": "10.03"
        }
      },
      "rate_info": {
        "score": 4.5,
        "review_count": "91316"
      },
      "sold_info": {
        "sold_count": 1235089
      },
      "seller_info": {
        "seller_id": "7495794203056835079",
        "shop_name": "Goli Nutrition",
        "shop_logo": {
          "height": 300,
          "width": 300,
          "uri": "tos-useast5-i-omjb5zjo8w-tx/e7478d3e93d4487a9e772fa74e10f506",
          "url_list": [
            "https://p16-oec-general-useast5.ttcdn-us.com/tos-useast5-i-omjb5zjo8w-tx/e7478d3e93d4487a9e772fa74e10f506~tplv-fhlh96nyum-resize-png:300:300.png?dr=12184&from=2422056039&idc=useast8&ps=933b5bde&shcp=d9d491bf&shp=905da467&t=555f072d"
          ]
        }
      },
      "seo_url": {
        "updated_at": "1754035613102",
        "canonical_url": "https://www.tiktok.com/shop/pdp/ashwagandha-gummies-by-goli-ksm-66-mixed-berry-vegan-non-gmo/1729527313880355335",
        "slug": "ashwagandha-gummies-by-goli-ksm-66-mixed-berry-vegan-non-gmo",
        "type": 2,
        "version": 2
      }
    }
  ]
}

Best Practices

Error Handling

Implement comprehensive error handling and retry logic for failed requests. Log errors properly for debugging.

Caching

Cache responses when possible to reduce API calls and improve performance. Consider data freshness requirements.

Security

Never expose your API key in client-side code. Use environment variables and secure key management practices.

Troubleshooting

401

Unauthorized

Check your API key is correct and properly formatted in the x-api-key header.

402

Payment Required

You ran out of credits and need to buy more.

404

Not Found

The resource (user, video, etc.) might not exist or be private.

429

Too Many Requests

You have exceeded your rate limit. Slow down your requests.

Frequently Asked Questions

How much does it cost to scrape TikTok Shop?

SociaVault offers 50 free API calls to get started. After that, pricing starts at $10 for 5k requests with volume discounts available.

Is it legal to scrape TikTok Shop data?

Scraping publicly available data is generally considered legal. We only collect public data that is accessible without logging in.

How fast can I scrape TikTok Shop?

Our API handles the rate limiting for you. You can make requests as fast as your plan allows.

What data format does the API return?

All API responses are returned in JSON format, making it easy to integrate with any programming language or application.

Related Tutorials

Ready to Start Scraping?

Get started with 50 free API calls. No credit card required. Stop worrying about proxies and captchas.