> ## 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

> Tích hợp API Ayrshare vào ứng dụng Node của bạn với Gói NPM Social API

## Tổng quan

[Gói NPM Social API](https://www.npmjs.com/package/social-media-api) của Ayrshare cho phép bạn tích hợp API Ayrshare vào ứng dụng Node.js của mình.

### Cài đặt

Cài đặt Gói NPM Social API nếu bạn sử dụng Node ở phía máy chủ.
Gói này đơn giản hóa các lệnh gọi bằng cách bao bọc các lệnh gọi RESTful.

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

<Info>Lấy API Key bí mật của bạn trong [Dashboard Ayrshare](https://app.ayrshare.com/).</Info>

### Sử dụng chung

Ví dụ về Post, History và Delete:

<Info>
  **Đăng bài lên X/Twitter?** Kể từ ngày 31 tháng 3 năm 2026, các thao tác X/Twitter thông qua Ayrshare yêu cầu thông tin đăng nhập X Developer App của riêng bạn — Ayrshare thực thi điều này trên mọi lệnh gọi đến X. Thêm 2 header BYO vào yêu cầu của bạn. Xem [hướng dẫn thiết lập](/dashboard/connect-social-accounts/x-twitter-byo-keys) để biết chi tiết.
</Info>

Kể từ v1.3.0, SDK bao gồm một trình trợ giúp `setTwitterByo(apiKey, apiSecret)` gắn hai header `X-Twitter-OAuth1-*` bắt buộc vào mọi yêu cầu tiếp theo:

```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"]
});
```

Sử dụng `clearTwitterByo()` để loại bỏ các header — hữu ích khi tái sử dụng một instance SDK trên nhiều tenant:

```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();
```

### Tổng quan Video về Gói NPM Social Media API

<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>

Đăng lên Mạng xã hội qua API

### Profile Key

Bạn có thể chỉ định Profile Key cho User Profile trong phần body của POST hoặc query của GET bằng trường `profileKey`.

### Demo Social API

Để xem ví dụ tích hợp Node.js (sử dụng các lệnh gọi API RESTful), hãy xem kho lưu trữ GitHub:

<Card title="Mã Demo Social API" icon="github" href="https://github.com/ayrshare/social-api-demo" horizontal>
  Social API Demo là một ứng dụng web cho phép người dùng soạn thảo, lên lịch và đăng nội dung
  lên nhiều nền tảng mạng xã hội đồng thời.
</Card>

### Thông tin và Tài liệu Bổ sung

<ul class="custom-bullets">
  <li>[Gói NPM](https://www.npmjs.com/package/social-media-api)</li>
  <li>[Kho lưu trữ Github](https://github.com/ayrshare/social-media-api)</li>
  <li>[Thảo luận vấn đề](https://github.com/ayrshare/social-media-api/issues)</li>
</ul>
