SDKs overview

Giphy offers Software Development Kits (SDKs) and community-contributed libraries to facilitate the integration of its GIF and sticker content into diverse applications. These tools are designed to simplify interaction with the Giphy API endpoints, providing developers with pre-built functions for tasks such as searching, fetching trending content, and displaying media. The availability of SDKs for major mobile platforms like iOS and Android, alongside various community-maintained libraries for web and server-side languages, enables broader accessibility to Giphy's content catalog.

The Giphy API itself is a RESTful interface, returning data primarily in JSON format, which allows for direct integration without an SDK if preferred. However, using an SDK can reduce boilerplate code and handle common tasks such as request signing and response parsing, which is a common benefit of SDKs across many APIs, as highlighted by Google Cloud's SDK overview. Developers can obtain an API key from the Giphy Developer Dashboard to begin using the API and associated SDKs.

Official SDKs by language

Giphy maintains official SDKs primarily for mobile platforms, reflecting the common use cases for GIF integration in messaging and social applications. These SDKs are developed and supported by Giphy to ensure compatibility with the latest API features and platform updates. The official SDKs abstract the underlying HTTP requests and JSON parsing, providing native language interfaces for developers.

The table below lists the officially supported SDKs and their associated details:

Language Package Name / Repo Installation Command (Example) Maturity
iOS (Swift/Objective-C) Giphy-iOS-SDK pod 'Giphy' (CocoaPods) or Swift Package Manager Stable
Android (Java/Kotlin) giphy-android-sdk implementation 'com.giphy.sdk:giphy-android-sdk:x.y.z' (Gradle) Stable

Installation

Installation methods vary depending on the target platform and language. For official SDKs, standard package managers are typically used.

iOS SDK Installation

The Giphy iOS SDK supports installation via CocoaPods or Swift Package Manager. Below are common installation steps:

CocoaPods

  1. Ensure CocoaPods is installed.
  2. Navigate to your Xcode project directory in the terminal.
  3. Create a Podfile if one doesn't exist: pod init
  4. Add the Giphy pod to your Podfile:
    target 'YourProjectName' do
      use_frameworks!
      pod 'Giphy'
    end
    
  5. Run pod install.
  6. Open your project's .xcworkspace file.

Swift Package Manager

  1. In Xcode, go to File > Add Packages...
  2. Enter the repository URL: https://github.com/Giphy/giphy-ios-sdk.git
  3. Select the desired version rule and add the package.

Android SDK Installation

The Giphy Android SDK is distributed through Maven Central and can be integrated using Gradle.

  1. Ensure your project's settings.gradle or settings.gradle.kts includes Maven Central:
    dependencyResolutionManagement {
        repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
        repositories {
            google()
            mavenCentral()
        }
    }
    
  2. Add the dependency to your app's build.gradle or build.gradle.kts file:
    dependencies {
        implementation 'com.giphy.sdk:giphy-android-sdk:x.y.z' // Replace x.y.z with the latest version
    }
    
  3. Synchronize your Gradle project.

Quickstart example

This quickstart demonstrates how to use the Giphy iOS SDK to display trending GIFs. A similar approach applies to the Android SDK, involving initialization and calling relevant methods.

iOS SDK Quickstart (Swift)

First, ensure you have obtained your API key from the Giphy Developer Dashboard. Initialize the SDK with your API key, then fetch and display trending GIFs.

import UIKit
import Giphy

class ViewController: UIViewController {

    // Assume you have a UIImageView outlet connected in your Storyboard/XIB
    @IBOutlet weak var gifImageView: UIImageView!

    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 1. Initialize Giphy SDK with your API Key
        Giphy.configure(apiKey: "YOUR_GIPHY_API_KEY")
        
        // 2. Fetch trending GIFs
        GiphyCore.shared.trending(mediaType: .gif, limit: 1, offset: 0, rating: .pg13, bundle: GiphyBundle.gphDefault) {
            (response, error) in
            
            if let error = error {
                print("Error fetching trending GIFs: \(error.localizedDescription)")
                return
            }
            
            guard let gif = response?.data?.first else {
                print("No trending GIFs found.")
                return
            }
            
            // 3. Display the GIF (assuming you have a GIF player library or a custom solution)
            // For simplicity, this example will just print the URL.
            // In a real app, you would use a library like FLAnimatedImage or Kingfisher to load and play the GIF.
            if let urlString = gif.images?.fixedWidth?.gifUrl,
               let url = URL(string: urlString) {
                print("Trending GIF URL: \(url)")
                // You would typically load this URL into a UIImageView supporting GIF playback
                // e.g., self.gifImageView.kf.setImage(with: url)
            }
        }
    }
}

This example initializes the Giphy SDK and retrieves the URL for a single trending GIF. To display the GIF visually, additional libraries capable of playing animated GIFs (e.g., FLAnimatedImage, Kingfisher) would typically be integrated into the iOS project.

Community libraries

Beyond the official SDKs, the Giphy API's RESTful nature has led to the development of numerous community-contributed libraries across various programming languages. These libraries often wrap the core API functionality, providing idiomatic interfaces for developers in their preferred environments. While not officially supported by Giphy, they can offer flexibility and cater to specific language ecosystems.

Examples of community libraries often found for Giphy include:

  • JavaScript/Node.js: Libraries that facilitate server-side or client-side interactions with the Giphy API, often available via npm.
  • Python: Wrappers that allow Python developers to easily search and retrieve GIFs, typically installed via pip.
  • Ruby: Gems that provide a Ruby-friendly interface to the Giphy API.
  • PHP: Packages available through Composer for PHP-based applications.
  • Java (non-Android specific): General-purpose Java libraries for backend applications.

Developers should consult the documentation and community repositories (e.g., GitHub, package managers) for the specific library they intend to use to understand its features, installation instructions, and maintenance status. These libraries often follow the patterns described in Mozilla's API documentation, offering a simplified way to interact with web services.

When using community libraries, it is advisable to check their last update date, open issues, and the activity of the maintainers to ensure ongoing support and compatibility with the latest Giphy API versions.