panda-tiktok is a Ruby gem that provides a client for interacting with the TikTok Ads API. It simplifies making authenticated requests to retrieve advertiser details, campaigns, ad groups, and ads while handling errors gracefully.
- Authentication and request handling for the TikTok Ads API.
- Retrieve advertisers, campaigns, ad groups, and ads.
- Fetch advertising reports with specified dimensions.
- Handle API errors with custom exceptions.
- Configuration support for API keys and base URLs.
Add this line to your application's Gemfile:
gem 'panda-tiktok'
Then, run:
bundle install
Alternatively, install it manually using:
gem install panda-tiktok
To configure the client, use the Panda.configure block:
require 'panda'
Panda.configure do |config|
config.app_id = 'your_app_id'
config.app_secret = 'your_app_secret'
config.api_version = 'v1.3'
end
To interact with the TikTok Ads API, initialize the client with an access token:
client = Panda::Client.new('your_access_token')
Fetch the list of advertisers associated with the access token:
advertisers = client.advertisers
Retrieve details about specific advertisers:
advertiser_info = client.advertiser_info(['advertiser_id_1', 'advertiser_id_2'])
Get all campaigns for an advertiser:
campaigns = client.campaigns('advertiser_id')
Fetch all ad groups for an advertiser:
ad_groups = client.ad_groups('advertiser_id')
Get all ads for an advertiser:
ads = client.ads('advertiser_id')
Retrieve advertising performance reports with specified dimensions:
report = client.report('advertiser_id', 'BASIC', ['campaign_id', 'adgroup_id'])
Retrieve the user profile associated with the access token:
user_info = client.user_info
Validate the current access token:
token_info = client.token_info
The gem raises custom exceptions for different error responses from the API:
Panda::APIError
: Generic API error.Panda::NoPermissionsError
: Raised when the user lacks the required permissions.Panda::NotAuthorizedError
: Raised for authentication failures.Panda::TooManyRequestsError
: Raised when rate limits are exceeded.
Example usage:
begin
campaigns = client.campaigns('advertiser_id')
rescue Panda::NotAuthorizedError => e
puts "Authorization error: #{e.message}"
rescue Panda::APIError => e
puts "API error: #{e.message}"
end
To contribute to the gem, clone the repository and install dependencies:
git clone https://github.com/revealbot/panda-tiktok.git
cd panda-tiktok
bundle install
Run tests:
bundle exec rspec
This gem is licensed under the MIT License. See the LICENSE file for more details.