SDKs overview

Ayrshare provides Software Development Kits (SDKs) and client libraries designed to facilitate integration with its social media API. These tools encapsulate the underlying HTTP-based RESTful API interactions, allowing developers to interact with Ayrshare's services using native language constructs rather than direct HTTP requests. The primary objective of these SDKs is to streamline common tasks such as publishing content to multiple social networks, retrieving post analytics, and managing user authentication.

The SDKs abstract away details like request formatting, response parsing, and error handling, providing a higher-level interface. This abstraction can reduce development time and potential errors when building applications that interact with social media platforms programmatically. Ayrshare offers official SDKs for several popular programming languages, ensuring broad support for development environments. Additionally, the platform's comprehensive API reference supports direct integration for languages without an official SDK, as detailed in the Ayrshare API reference documentation.

Official SDKs by language

Ayrshare maintains official SDKs for widely used programming languages, providing tested and supported client libraries. These SDKs are developed and maintained by Ayrshare to ensure compatibility with the latest API versions and features. Each SDK aims to offer an idiomatic interface for its respective language, making integration straightforward for developers familiar with that ecosystem.

The following table outlines the official SDKs, their package names, and typical installation commands:

Language Package/Library Name Install Command Maturity
Node.js ayrshare npm install ayrshare or yarn add ayrshare Stable
PHP ayrshare/ayrshare-php composer require ayrshare/ayrshare-php Stable
Python ayrshare pip install ayrshare Stable
Ruby ayrshare gem install ayrshare Stable
Go github.com/ayrshare/go-sdk go get github.com/ayrshare/go-sdk Stable

These SDKs are designed to mirror the functionality available through the Ayrshare API documentation, offering methods for common operations such as publishing posts, managing media, and retrieving analytics data. Developers can find detailed usage instructions and examples within the respective SDK repositories or the Ayrshare developer documentation.

Installation

Installing an Ayrshare SDK typically involves using the package manager specific to the programming language. The process is designed to be standard for each ecosystem, integrating seamlessly into existing development workflows. Before installation, developers should ensure they have the correct runtime environment and package manager configured.

Node.js Installation

For Node.js projects, the ayrshare package is available via npm or Yarn. Navigate to your project directory and execute one of the following commands:

npm install ayrshare
# or
yarn add ayrshare

This command downloads the package and its dependencies, making the Ayrshare client available for import in your JavaScript or TypeScript files. The Node.js SDK supports both CommonJS and ES module syntax.

PHP Installation

PHP projects typically use Composer for dependency management. To install the Ayrshare PHP SDK, run the following command in your project's root directory:

composer require ayrshare/ayrshare-php

Composer will add the ayrshare/ayrshare-php package to your composer.json file and install it into your vendor directory. Remember to include Composer's autoloader in your application: require 'vendor/autoload.php';

Python Installation

Python developers can install the Ayrshare SDK using pip, the standard Python package installer. It is recommended to use a virtual environment to manage project dependencies.

pip install ayrshare

After installation, you can import the ayrshare module in your Python scripts. The Python SDK provides an object-oriented interface for interacting with the API.

Ruby Installation

For Ruby projects, the Ayrshare gem can be installed using the RubyGems package manager:

gem install ayrshare

Alternatively, you can add it to your Gemfile and run bundle install:

# Gemfile
gem 'ayrshare'

Then, require the gem in your Ruby application: require 'ayrshare'.

Go Installation

Go developers can retrieve the Ayrshare Go SDK using the go get command:

go get github.com/ayrshare/go-sdk

Once installed, you can import the package into your Go source files and utilize its functions to interact with the Ayrshare API. Ensure your Go module is initialized if you are working within a module-aware project.

Quickstart example

This quickstart example demonstrates how to publish a simple text post to social media using the Node.js SDK. This example assumes you have already installed the Node.js SDK and have an API key from your Ayrshare account.

Node.js Quickstart: Publishing a Text Post

First, ensure you have your Ayrshare API key. This key authenticates your requests to the Ayrshare API. It is recommended to store your API key securely, for example, using environment variables, rather than hardcoding it directly in your application code.

const Ayrshare = require('ayrshare');

// Initialize Ayrshare with your API key
// Replace 'YOUR_API_KEY' with your actual Ayrshare API key
const ayrshare = new Ayrshare('YOUR_API_KEY');

const postData = {
  post: 'Hello, world! This is a test post from Ayrshare SDK.',
  platforms: ['facebook', 'twitter', 'linkedin'] // Specify target platforms
};

async function publishPost() {
  try {
    const response = await ayrshare.post.post(postData);
    console.log('Post successful:', response.data);
    // The response.data object contains details like postId, status, and platform-specific IDs.
    // For example, response.data.id for the Ayrshare post ID, or response.data.postIds for platform-specific IDs.

    if (response.data.status === 'success') {
      console.log('Post ID:', response.data.id);
      response.data.postIds.forEach(platformPost => {
        console.log(`Platform: ${platformPost.platform}, Post URL: ${platformPost.postUrl}`);
      });
    } else {
      console.error('Post failed:', response.data.errors);
    }

  } catch (error) {
    if (error.response) {
      // The request was made and the server responded with a status code
      // that falls out of the range of 2xx
      console.error('API Error Response:', error.response.data);
      console.error('API Error Status:', error.response.status);
      console.error('API Error Headers:', error.response.headers);
    } else if (error.request) {
      // The request was made but no response was received
      console.error('API Error Request:', error.request);
    } else {
      // Something happened in setting up the request that triggered an Error
      console.error('Error Message:', error.message);
    }
    console.error('Error config:', error.config);
  }
}

publishPost();

This example initializes the Ayrshare client with an API key and then calls the post.post method with a simple text message and an array of target social media platforms. The await keyword ensures that the program waits for the API response before proceeding. Error handling is included to catch potential issues during the API call, such as network errors or invalid API responses. For more complex posting scenarios, such as including images or videos, scheduling posts for a future time, or retrieving detailed analytics, refer to the full Ayrshare API reference and specific SDK documentation.

Community libraries

While Ayrshare provides official SDKs for several languages, the broader developer community may contribute unofficial libraries or wrappers that extend functionality or support additional programming languages and frameworks. These community-driven efforts can sometimes offer alternative approaches to integration or cater to niche requirements not covered by official SDKs.

Community libraries are not officially supported or maintained by Ayrshare. Their quality, reliability, and security can vary. Developers considering using a community library should:

  • Evaluate the Source: Check the repository's activity, contributor base, and issue tracker.
  • Review Documentation: Ensure comprehensive documentation is available for installation and usage.
  • Examine Code: Inspect the source code for best practices, security vulnerabilities, and adherence to the Ayrshare API specifications.
  • Test Thoroughly: Conduct extensive testing to confirm functionality and stability within your application.

As of the current date, Ayrshare primarily promotes its official SDKs. For the most up-to-date information on community contributions, developers are encouraged to explore public code repositories like GitHub, search package managers (e.g., npm, PyPI, RubyGems) for packages related to 'Ayrshare API', or consult developer forums and communities where Ayrshare users interact. The official Ayrshare documentation remains the authoritative source for API specifications and best practices, applicable whether using an official SDK or a community-developed tool.