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

# Python PyPI

> Gói client Python PyPI cho Ayrshare

## Tổng quan

[Gói PyPI Social-Post-API](https://pypi.org/project/social-post-api/) của Ayrshare cho phép bạn tích hợp API Ayrshare vào ứng dụng Python của mình.

### Cài đặt

Cài đặt [Gói PyPI Social-Post-API](https://pypi.org/project/social-post-api/) nếu bạn sử dụng Python ở 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.

Bắt đầu bằng cách lấy API Key bí mật của bạn tại [Dashboard Ayrshare](https://app.ayrshare.com/api).

Tiếp theo, cài đặt gói Python:

```bash theme={"system"}
pip install social-post-api
```

### Sử dụng chung

Ví dụ về Post, History và Delete. Vui lòng xem [Gói PyPI](https://pypi.org/project/social-post-api/) để biết thêm thông tin.

<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 `set_twitter_byo(api_key, api_secret)` gắn hai header `X-Twitter-OAuth1-*` bắt buộc vào mọi yêu cầu tiếp theo:

```python theme={"system"}
from ayrshare import SocialPost

social = SocialPost(API_KEY)
social.set_twitter_byo(MY_X_API_KEY, MY_X_API_SECRET)

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

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

```python theme={"system"}
social.clear_twitter_byo().set_twitter_byo(next_tenant_key, next_tenant_secret)
```

```python theme={"system"}
from ayrshare import SocialPost
social = SocialPost('8jKj782Aw8910dCN') # get an API Key at ayrshare.com

# Required for any post that includes 'twitter' in platforms (BYO is enforced).
social.set_twitter_byo('YOUR_X_CONSUMER_KEY', 'YOUR_X_CONSUMER_SECRET')

# Post to Platforms Twitter, Facebook, and LinkedIn
postResult = social.post({'post': 'Nice Posting 2', 'platforms': ['twitter', 'facebook', 'linkedin'], 'profileKey': 'JKSDJI-JKKJKKJ'})
print(postResult)

# Delete (use the top-level Ayrshare post id from postResult['id'])
deleteResult = social.delete({'id': postResult['id']})
print(deleteResult)

# History
print(social.history())
```

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

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

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