curl \
-H "Authorization: Bearer API_KEY" \
-H 'Content-Type: application/json' \
-H "X-Twitter-OAuth1-Api-Key: YOUR_CONSUMER_KEY" \
-H "X-Twitter-OAuth1-Api-Secret: YOUR_CONSUMER_SECRET" \
-d '{"profileKey": "PROFILE_KEY"}' \
-X POST https://api.ayrshare.com/api/profiles/generateJWT
const API_KEY = "API_KEY";
const PROFILE_KEY = "PROFILE_KEY";
fetch("https://api.ayrshare.com/api/profiles/generateJWT", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${API_KEY}`,
"X-Twitter-OAuth1-Api-Key": "YOUR_CONSUMER_KEY",
"X-Twitter-OAuth1-Api-Secret": "YOUR_CONSUMER_SECRET"
},
body: JSON.stringify({
profileKey: PROFILE_KEY, // required
}),
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
payload = {'profileKey': 'PROFILE_KEY'}
headers = {'Content-Type': 'application/json',
'Authorization': 'Bearer API_KEY',
'X-Twitter-OAuth1-Api-Key': 'YOUR_CONSUMER_KEY',
'X-Twitter-OAuth1-Api-Secret': 'YOUR_CONSUMER_SECRET'}
r = requests.post('https://api.ayrshare.com/api/profiles/generateJWT',
json=payload,
headers=headers)
print(r.json())
<?php
require 'vendor/autoload.php'; // Composer auto-loader using Guzzle. See .../guzzlephp.org/en/stable/overview.html
$client = new GuzzleHttp\Client();
$res = $client->request(
'POST',
'https://api.ayrshare.com/api/profiles/generateJWT',
[
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer API_KEY'
],
'json' => [
'profileKey' => 'PROFILE_KEY', // required
]
]
);
echo json_encode(json_decode($res->getBody()), JSON_PRETTY_PRINT);
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace GenerateJWTRequest_csharp
{
class GenerateJWT
{
static async Task Main(string[] args)
{
string API_KEY = "API_KEY";
string url = "https://api.ayrshare.com/api/profiles/generateJWT";
try
{
var sendData = new
{
profileKey = "PROFILE_KEY"
};
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + API_KEY);
string jsonData = JsonConvert.SerializeObject(sendData);
var content = new StringContent(jsonData, Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync(url, content);
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
}
catch (HttpRequestException e)
{
Console.WriteLine($"HTTP request error: {e.Message}");
}
catch (Exception e)
{
Console.WriteLine($"Unexpected error: {e.Message}");
}
}
}
}
{
"status": "success",
"title": "User Profile Title",
"token": "ayr_ls_kJ8mQ2vX9pLnR4tYwZ6aBcD1eFgH3iJkLmN0oPqRsTu",
"url": "https://profile.ayrshare.com?session=ayr_ls_kJ8mQ2vX9pLnR4tYwZ6aBcD1eFgH3iJkLmN0oPqRsTu&domain=PROVIDED_DOMAIN",
"emailSent": true,
"expiresIn": "5m"
}
{
"status": "success",
"title": "User Profile Title",
"token": "ayr_ls_kJ8mQ2vX9pLnR4tYwZ6aBcD1eFgH3iJkLmN0oPqRsTu",
"url": "https://profile.ayrshare.com?session=ayr_ls_kJ8mQ2vX9pLnR4tYwZ6aBcD1eFgH3iJkLmN0oPqRsTu&domain=PROVIDED_DOMAIN",
"emailSent": false,
"emailError": {
"code": 333,
"message": "Email failed to send. Please confirm a valid email was provided."
},
"expiresIn": "5m"
}
{
"action": "JWT",
"status": "error",
"code": 189,
"message": "Error generating JWT. Check the sent parameters.",
"details": "Missing or incorrect domain."
}
{
"action": "JWT",
"status": "error",
"code": 188,
"message": "Both twitterApiKey and twitterApiSecret are required. You provided only one."
}
{
"action": "JWT",
"status": "error",
"code": 434,
"message": "X/Twitter API credentials were provided in both the request headers and the request body. Please use the headers only. See https://www.ayrshare.com/docs/apis/profiles/generate-jwt"
}
Profiles
Tạo URL liên kết (generateJWT)
Tạo URL liên kết mạng xã hội cho một User Profile bằng endpoint generateJWT.
POST
/
profiles
/
generateJWT
curl \
-H "Authorization: Bearer API_KEY" \
-H 'Content-Type: application/json' \
-H "X-Twitter-OAuth1-Api-Key: YOUR_CONSUMER_KEY" \
-H "X-Twitter-OAuth1-Api-Secret: YOUR_CONSUMER_SECRET" \
-d '{"profileKey": "PROFILE_KEY"}' \
-X POST https://api.ayrshare.com/api/profiles/generateJWT
const API_KEY = "API_KEY";
const PROFILE_KEY = "PROFILE_KEY";
fetch("https://api.ayrshare.com/api/profiles/generateJWT", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${API_KEY}`,
"X-Twitter-OAuth1-Api-Key": "YOUR_CONSUMER_KEY",
"X-Twitter-OAuth1-Api-Secret": "YOUR_CONSUMER_SECRET"
},
body: JSON.stringify({
profileKey: PROFILE_KEY, // required
}),
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
payload = {'profileKey': 'PROFILE_KEY'}
headers = {'Content-Type': 'application/json',
'Authorization': 'Bearer API_KEY',
'X-Twitter-OAuth1-Api-Key': 'YOUR_CONSUMER_KEY',
'X-Twitter-OAuth1-Api-Secret': 'YOUR_CONSUMER_SECRET'}
r = requests.post('https://api.ayrshare.com/api/profiles/generateJWT',
json=payload,
headers=headers)
print(r.json())
<?php
require 'vendor/autoload.php'; // Composer auto-loader using Guzzle. See .../guzzlephp.org/en/stable/overview.html
$client = new GuzzleHttp\Client();
$res = $client->request(
'POST',
'https://api.ayrshare.com/api/profiles/generateJWT',
[
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer API_KEY'
],
'json' => [
'profileKey' => 'PROFILE_KEY', // required
]
]
);
echo json_encode(json_decode($res->getBody()), JSON_PRETTY_PRINT);
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace GenerateJWTRequest_csharp
{
class GenerateJWT
{
static async Task Main(string[] args)
{
string API_KEY = "API_KEY";
string url = "https://api.ayrshare.com/api/profiles/generateJWT";
try
{
var sendData = new
{
profileKey = "PROFILE_KEY"
};
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + API_KEY);
string jsonData = JsonConvert.SerializeObject(sendData);
var content = new StringContent(jsonData, Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync(url, content);
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
}
catch (HttpRequestException e)
{
Console.WriteLine($"HTTP request error: {e.Message}");
}
catch (Exception e)
{
Console.WriteLine($"Unexpected error: {e.Message}");
}
}
}
}
{
"status": "success",
"title": "User Profile Title",
"token": "ayr_ls_kJ8mQ2vX9pLnR4tYwZ6aBcD1eFgH3iJkLmN0oPqRsTu",
"url": "https://profile.ayrshare.com?session=ayr_ls_kJ8mQ2vX9pLnR4tYwZ6aBcD1eFgH3iJkLmN0oPqRsTu&domain=PROVIDED_DOMAIN",
"emailSent": true,
"expiresIn": "5m"
}
{
"status": "success",
"title": "User Profile Title",
"token": "ayr_ls_kJ8mQ2vX9pLnR4tYwZ6aBcD1eFgH3iJkLmN0oPqRsTu",
"url": "https://profile.ayrshare.com?session=ayr_ls_kJ8mQ2vX9pLnR4tYwZ6aBcD1eFgH3iJkLmN0oPqRsTu&domain=PROVIDED_DOMAIN",
"emailSent": false,
"emailError": {
"code": 333,
"message": "Email failed to send. Please confirm a valid email was provided."
},
"expiresIn": "5m"
}
{
"action": "JWT",
"status": "error",
"code": 189,
"message": "Error generating JWT. Check the sent parameters.",
"details": "Missing or incorrect domain."
}
{
"action": "JWT",
"status": "error",
"code": 188,
"message": "Both twitterApiKey and twitterApiSecret are required. You provided only one."
}
{
"action": "JWT",
"status": "error",
"code": 434,
"message": "X/Twitter API credentials were provided in both the request headers and the request body. Please use the headers only. See https://www.ayrshare.com/docs/apis/profiles/generate-jwt"
}
Tạo URL liên kết mạng xã hội cho một User Profile. Endpoint vẫn có tên
generateJWT, nhưng token nó trả về là chuỗi không giải mã được và không phải JWT.
Xem Tổng quan Liên kết Mạng xã hội để biết thêm chi tiết.
URL liên kết có hiệu lực trong 5 phút. Sau 5 phút bạn phải tạo URL liên kết mới.
Xem Max Pack
expiresIn để biết các tùy chọn bổ sung.Endpoint này đã ngừng khuyến nghị (deprecated). Nó vẫn được hỗ trợ đầy đủ, không có ngày
gỡ bỏ, và tiếp tục hoạt động không thay đổi — nó chỉ đơn giản là không còn là cách được khuyến
nghị để tạo URL liên kết.
token trả về là một chuỗi không thể giải mã bắt đầu bằng ayr_ls_: nó không phải
JWT có thể decode và không chứa payload đọc được. Hãy chuyển url cho người dùng đúng như
khi trả về, và xem token như một thông tin xác thực bạn lưu lại chứ không phải để phân
tích. Các liên kết bạn đã tạo trước đó vẫn hoạt động.POST /profiles/link-sessions thực hiện cùng một thao tác mà không cần các tham số cũ, và
còn cho phép bạn kiểm tra hoặc thu hồi một liên kết. Xem
Tạo một Link Session.Tham số Header
string
X API Key (Consumer Key) của bạn từ X Developer Portal. Thay thế cho tham số body
twitterApiKey. Khi được cung cấp, URL liên kết được tạo sẽ sử dụng X Developer App của bạn cho liên kết OAuth.string
X API Secret (Consumer Secret) của bạn từ X Developer Portal. Thay thế cho tham số body
twitterApiSecret. Bắt buộc khi X-Twitter-OAuth1-Api-Key được cung cấp.Khuyến nghị: Truyền thông tin xác thực X qua header (
X-Twitter-OAuth1-Api-Key và X-Twitter-OAuth1-Api-Secret) để nhất quán với tất cả các endpoint API Ayrshare khác. Các tham số body twitterApiKey và twitterApiSecret vẫn được hỗ trợ để tương thích ngược.Tham số Body
string
Miền của ứng dụng. Vui lòng sử dụng chính xác miền được cấp trong quá trình onboarding.Không bắt buộc. Nếu bỏ trống, domain của chính tài khoản bạn sẽ được dùng. Nếu bạn gửi, đó phải là domain đã đăng ký cho tài khoản của bạn.
string
không còn sử dụng
Không còn được dùng. Trường này vẫn được chấp nhận và bị bỏ qua, nên các tích hợp hiện có tiếp tục hoạt động mà không cần thay đổi.URL liên kết không còn được ký nữa, nên không có khóa nào cần gửi. Bạn có thể bỏ trường này và ngừng lưu private key cho mục đích này.
string
bắt buộc
User Profile Key. API Key không thể được sử dụng trong trường này.
boolean
mặc định:false
Tự động đăng xuất phiên hiện tại. Không khuyến nghị sử dụng trong production vì nó ảnh hưởng đến hiệu suất.Xem Tự động đăng xuất phiên Profile để biết thêm thông tin.
string
Chỉ định một URL để chuyển hướng đến khi nút “Done” hoặc hình ảnh logo được nhấp. URL sẽ tự động được rút gọn trong URL liên kết được trả về. Chuyển hướng cửa sổ opener gốc bằng cách thêm tham số truy vấn
origin=true vào URL chuyển hướng.array
Chỉ định các mạng xã hội hiển thị trong trang liên kết. Điều này sẽ ghi đè các mạng xã hội được cấu hình trong trang Social Networks.
Only display Facebook, X/Twitter, LinkedIn, and TikTok
{
"allowedSocial": ["facebook", "twitter", "linkedin", "tiktok"]
}
string
Ghi đè luồng liên kết Instagram nào được sử dụng khi người dùng nhấp vào nút Instagram trên trang liên kết mạng xã hội cho URL này. Các giá trị hợp lệ:Khi bị bỏ qua, trang liên kết sử dụng cài đặt Instagram Login toàn tài khoản của bạn.Xem Phương thức liên kết Instagram để biết thêm thông tin.
instagram: Instagram Login trực tiếp, không yêu cầu Facebook Page.facebook: Liên kết Instagram thông qua Facebook Page đã kết nối.
Force direct Instagram Login for this linking session
{
"instagramLinkMethod": "instagram"
}
boolean
không còn sử dụng
Không còn được dùng. Trường này vẫn được chấp nhận và bị bỏ qua.Không còn token đã ký nào để xác minh:
token trả về được trang liên kết xác thực khi người dùng của bạn mở URL.boolean
không còn sử dụng
Không còn được dùng. Trường này vẫn được chấp nhận và bị bỏ qua, vì
privateKey không còn được đọc.number
mặc định:5
Đặt thời hạn của token tính bằng phút. Phạm vi: 1 phút đến 2880 phút.Xem Thời hạn Liên kết để biết thêm thông tin.
object
Gửi email Connect Accounts với một liên kết để người dùng truy cập trực tiếp vào trang liên kết mạng xã hội của họ.Nếu không gửi được email, bạn vẫn nhận được liên kết. Phản hồi có
emailSent: false và một đối tượng emailError, để bạn có thể gửi liên kết cho người dùng theo cách khác.Xem Connect Accounts Email để biết thêm thông tin.Khi bạn bao gồm thông tin xác thực X API của mình, URL liên kết được tạo sẽ khởi tạo liên kết OAuth bằng X Developer App của riêng bạn. Người dùng cuối của bạn sẽ thấy tên ứng dụng của bạn trên màn hình đồng ý X.
Bắt buộc: Trước khi sử dụng tính năng này, bạn phải thêm các URL callback này vào cài đặt X Developer App của mình (trong Authentication settings > Callback URI / Redirect URL):
https://profile.ayrshare.com/social-accountshttps://app.ayrshare.com/social-accounts
403 Callback URL not approved.curl \
-H "Authorization: Bearer API_KEY" \
-H 'Content-Type: application/json' \
-H "X-Twitter-OAuth1-Api-Key: YOUR_CONSUMER_KEY" \
-H "X-Twitter-OAuth1-Api-Secret: YOUR_CONSUMER_SECRET" \
-d '{"profileKey": "PROFILE_KEY"}' \
-X POST https://api.ayrshare.com/api/profiles/generateJWT
const API_KEY = "API_KEY";
const PROFILE_KEY = "PROFILE_KEY";
fetch("https://api.ayrshare.com/api/profiles/generateJWT", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${API_KEY}`,
"X-Twitter-OAuth1-Api-Key": "YOUR_CONSUMER_KEY",
"X-Twitter-OAuth1-Api-Secret": "YOUR_CONSUMER_SECRET"
},
body: JSON.stringify({
profileKey: PROFILE_KEY, // required
}),
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
payload = {'profileKey': 'PROFILE_KEY'}
headers = {'Content-Type': 'application/json',
'Authorization': 'Bearer API_KEY',
'X-Twitter-OAuth1-Api-Key': 'YOUR_CONSUMER_KEY',
'X-Twitter-OAuth1-Api-Secret': 'YOUR_CONSUMER_SECRET'}
r = requests.post('https://api.ayrshare.com/api/profiles/generateJWT',
json=payload,
headers=headers)
print(r.json())
<?php
require 'vendor/autoload.php'; // Composer auto-loader using Guzzle. See .../guzzlephp.org/en/stable/overview.html
$client = new GuzzleHttp\Client();
$res = $client->request(
'POST',
'https://api.ayrshare.com/api/profiles/generateJWT',
[
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer API_KEY'
],
'json' => [
'profileKey' => 'PROFILE_KEY', // required
]
]
);
echo json_encode(json_decode($res->getBody()), JSON_PRETTY_PRINT);
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace GenerateJWTRequest_csharp
{
class GenerateJWT
{
static async Task Main(string[] args)
{
string API_KEY = "API_KEY";
string url = "https://api.ayrshare.com/api/profiles/generateJWT";
try
{
var sendData = new
{
profileKey = "PROFILE_KEY"
};
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + API_KEY);
string jsonData = JsonConvert.SerializeObject(sendData);
var content = new StringContent(jsonData, Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync(url, content);
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
}
catch (HttpRequestException e)
{
Console.WriteLine($"HTTP request error: {e.Message}");
}
catch (Exception e)
{
Console.WriteLine($"Unexpected error: {e.Message}");
}
}
}
}
{
"status": "success",
"title": "User Profile Title",
"token": "ayr_ls_kJ8mQ2vX9pLnR4tYwZ6aBcD1eFgH3iJkLmN0oPqRsTu",
"url": "https://profile.ayrshare.com?session=ayr_ls_kJ8mQ2vX9pLnR4tYwZ6aBcD1eFgH3iJkLmN0oPqRsTu&domain=PROVIDED_DOMAIN",
"emailSent": true,
"expiresIn": "5m"
}
{
"status": "success",
"title": "User Profile Title",
"token": "ayr_ls_kJ8mQ2vX9pLnR4tYwZ6aBcD1eFgH3iJkLmN0oPqRsTu",
"url": "https://profile.ayrshare.com?session=ayr_ls_kJ8mQ2vX9pLnR4tYwZ6aBcD1eFgH3iJkLmN0oPqRsTu&domain=PROVIDED_DOMAIN",
"emailSent": false,
"emailError": {
"code": 333,
"message": "Email failed to send. Please confirm a valid email was provided."
},
"expiresIn": "5m"
}
{
"action": "JWT",
"status": "error",
"code": 189,
"message": "Error generating JWT. Check the sent parameters.",
"details": "Missing or incorrect domain."
}
{
"action": "JWT",
"status": "error",
"code": 188,
"message": "Both twitterApiKey and twitterApiSecret are required. You provided only one."
}
{
"action": "JWT",
"status": "error",
"code": 434,
"message": "X/Twitter API credentials were provided in both the request headers and the request body. Please use the headers only. See https://www.ayrshare.com/docs/apis/profiles/generate-jwt"
}