> ## Documentation Index
> Fetch the complete documentation index at: https://www.ayrshare.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Node.js NPM

> Social API NPM PackageでAyrshare APIをNodeアプリに統合する

## 概要

Ayrshareの[Social API NPM Package](https://www.npmjs.com/package/social-media-api)を使うと、Ayrshare APIをNode.jsアプリに統合できます。

### インストール

サーバーサイドでNodeを使用している場合は、Social API NPM Packageをインストールしてください。
このパッケージはRESTful呼び出しをラップすることで、呼び出しを簡略化します。

```bash theme={"system"}
npm i social-media-api
```

<Info>シークレットAPIキーは[Ayrshareダッシュボード](https://app.ayrshare.com/)で取得します。</Info>

### 一般的な使い方

投稿、履歴、削除の例:

<Info>
  **X/Twitterへの投稿？** 2026年3月31日以降、Ayrshare経由のX/Twitter操作には独自のX Developer Appの認証情報が必要です — Ayrshareはすべてのx向けの呼び出しでこれを強制します。リクエストに2つのBYOヘッダーを追加してください。詳細は[セットアップガイド](/dashboard/connect-social-accounts/x-twitter-byo-keys)を参照してください。
</Info>

v1.3.0以降、SDKには`setTwitterByo(apiKey, apiSecret)`ヘルパーが含まれており、以降のすべてのリクエストに必要な2つの`X-Twitter-OAuth1-*`ヘッダーをアタッチします:

```javascript theme={"system"}
const SocialPost = require("social-media-api");
const social = new SocialPost(API_KEY)
  .setTwitterByo(MY_X_API_KEY, MY_X_API_SECRET);

await social.post({
  post: "Hello from BYO",
  platforms: ["twitter"]
});
```

`clearTwitterByo()`でヘッダーを削除できます — 1つのSDKインスタンスを複数のテナント間で再利用する場合に便利です:

```javascript theme={"system"}
social.clearTwitterByo().setTwitterByo(nextTenant.key, nextTenant.secret);
```

```javascript theme={"system"}
const SocialPost = require("social-media-api");
const API_KEY = "API KEY"; // get an API Key at ayrshare.com
const social = new SocialPost(API_KEY);

const run = async () => {
  /** post */
  const post = await social
    .post({
      post: "One more time",
      platforms: ["twitter", "facebook", "linkedin"],
      profileKey: "DJKJDK-SKDJKDJF" // used with a User Profile
    })
    .catch(console.error);
  console.log(post);

  /** history */
  const history = await social.history().catch(console.error);
  console.log(history);

  /** delete */
  const deletePost = await social.delete({ id: post.id }).catch(console.error);
  console.log(deletePost);
};

run();
```

### Social Media API NPM Packageのビデオ概要

<div class="video-container">
  <iframe width="560" height="315" src="https://www.youtube.com/embed/OMtj2h6sW6U" title="Social Media API NPM Package" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen />
</div>

APIを介したソーシャルメディア投稿

### Profile Key

POSTのボディまたはGETのクエリで`profileKey`フィールドを使用して、User ProfileのProfile Keyを指定できます。

### Social APIデモ

Node.js統合のサンプル（RESTful API呼び出しを使用）については、GitHubリポジトリをご覧ください:

<Card title="Social APIデモコード" icon="github" href="https://github.com/ayrshare/social-api-demo" horizontal>
  Social APIデモは、複数のソーシャルメディアプラットフォームに同時にコンテンツを作成、スケジュール設定、投稿できるWebアプリケーションです。
</Card>

### 追加情報とドキュメント

<ul class="custom-bullets">
  <li>[NPM Package](https://www.npmjs.com/package/social-media-api)</li>
  <li>[Githubリポジトリ](https://github.com/ayrshare/social-media-api)</li>
  <li>[Issueディスカッション](https://github.com/ayrshare/social-media-api/issues)</li>
</ul>
