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/post',
[
'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"
}
{
"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
產生連結 URL (generateJWT)
使用 generateJWT 端點為 User Profile 建立社群帳號連結 URL。
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/post',
[
'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"
}
{
"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"
}
為 User Profile 建立社群帳號連結 URL。該端點仍名為
generateJWT,但它返回的 token 是不透明字串,並不是 JWT。
詳情請參閱 連結 URL 概覽。
連結 URL 的有效期為 5 分鐘。5 分鐘後你必須產生新的連結 URL。
其他選項請參閱 Max Pack 的
expiresIn 設定。返回的
token 是以 ayr_ls_ 開頭的不透明字串,它不是可解碼的 JWT,也不含可讀的
payload。請將 url 原樣交給你的使用者,並把 token 視為需要保存而非解析的憑證。先前建立的
連結仍然有效。POST /profiles/link-sessions 執行相同的操作,但不需要這些舊參數,還可以查詢或撤銷某個連結。
參見建立 Link Session。標頭參數
string
你從 X Developer Portal 取得的 X API Key(Consumer Key)。是
twitterApiKey body 參數的替代方式。當提供時,產生的連結 URL 將使用你自己的 X Developer App 進行 OAuth 連結。string
你從 X Developer Portal 取得的 X API Secret(Consumer Secret)。是
twitterApiSecret body 參數的替代方式。當提供了 X-Twitter-OAuth1-Api-Key 時為必填。**建議:**透過標頭(
X-Twitter-OAuth1-Api-Key 與 X-Twitter-OAuth1-Api-Secret)傳遞你的 X 認證資料,以便與所有其他 Ayrshare API 端點的做法保持一致。為了向下相容,仍然支援 twitterApiKey 與 twitterApiSecret body 參數。Body 參數
string
App 的網域。請使用你在導入期間所取得的確切網域。選填。省略時會使用你帳戶本身的網域。若要傳送,必須是已註冊到你帳戶的網域。
string
已棄用
已不再使用。此欄位仍會被接受並忽略,因此現有整合無需變更即可繼續運作。連結 URL 不再簽署,因此不需要傳送任何金鑰。你可以移除此欄位,並不再為此保存 private key。
string
必填
User Profile Key。此欄位不能使用 API Key。
boolean
預設值:false
自動登出目前的工作階段。建議不要在正式環境中使用,因為會影響效能。更多資訊請參閱自動登出 Profile 工作階段。
string
指定當使用者點擊「Done」按鈕或 Logo 圖片時要轉向的 URL。該 URL 會在回傳的連結 URL 中自動被縮短。若要轉向原始開啟者視窗,請在 redirect URL 中加入
origin=true 查詢參數。array
指定要在連結頁面上顯示的社群網路。此設定會覆寫 Social Networks 頁面所設定的社群網路。
Only display Facebook, X/Twitter, LinkedIn, and TikTok
{
"allowedSocial": ["facebook", "twitter", "linkedin", "tiktok"]
}
string
針對此 URL,覆寫使用者在社群連結頁面點擊 Instagram 按鈕時所使用的 Instagram 連結流程。有效值:若省略此欄位,連結頁面將沿用你的帳號層級 Instagram Login 設定。更多資訊請參閱 Instagram 連結方式。
instagram:直接的 Instagram Login,不需 Facebook 粉絲專頁。facebook:透過已連結的 Facebook 粉絲專頁連結 Instagram。
Force direct Instagram Login for this linking session
{
"instagramLinkMethod": "instagram"
}
boolean
已棄用
已不再使用。此欄位仍會被接受並忽略。沒有需要驗證的簽署 token:返回的
token 會在你的使用者開啟該 URL 時由連結頁面驗證。boolean
已棄用
已不再使用。由於不再讀取
privateKey,此欄位仍會被接受並忽略。number
預設值:5
設定 Token 的有效期,單位為分鐘。範圍:1 分鐘至 2880 分鐘。更多資訊請參閱 JWT Expires In。
object
預設值:5
寄送 Connect Accounts 電子郵件,內含可讓使用者直接前往社群連結頁面的連結。更多資訊請參閱 Connect Accounts 電子郵件。
當你附上 X API 認證資料時,產生的連結 URL 將以你自己的 X Developer App 啟動 OAuth 連結流程。你的終端使用者會在 X 的授權同意畫面上看到你的 App 名稱。
**必要條件:**在使用此功能之前,你必須在 X Developer App 設定中(Authentication settings > Callback URI / Redirect URL)加入以下回呼 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/post',
[
'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"
}
{
"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"
}