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

# 创建 User Profile

> 在你的 Primary Profile 下创建一个新的 User Profile。

export const PlansAvailable = ({plans = [], maxPackRequired}) => {
  let displayPlans = plans;
  if (plans && plans.length === 1) {
    const lowerCasePlan = plans[0].toLowerCase();
    if (lowerCasePlan === "business") {
      displayPlans = ["Launch", "Business", "Enterprise"];
    } else if (lowerCasePlan === "premium") {
      displayPlans = ["Premium", "Launch", "Business", "Enterprise"];
    }
  }
  return <Note>
Available on {displayPlans.length === 1 ? "the " : ""}
{displayPlans.join(", ").replace(/\b\w/g, l => l.toUpperCase())}{" "}
{displayPlans.length > 1 ? "plans" : "plan"}.

{maxPackRequired && <span onClick={() => window.open('https://www.ayrshare.com/docs/additional/maxpack', '_self')} className="flex items-center mt-2 cursor-pointer">
 <span className="px-1.5 py-0.5 rounded text-sm" style={{
    backgroundColor: '#C264B6',
    color: 'white',
    fontSize: '12px'
  }}>
   Max Pack required
 </span>
</span>}
</Note>;
};

export const HeaderAPI = ({noProfileKey, profileKeyRequired}) => <>
    <ParamField header="Authorization" type="string" required>
      <a href="/apis/overview#authorization">API Key</a> of the Primary Profile.
      <br />
      <br />
      Format: <code>Authorization: Bearer API_KEY</code>
    </ParamField>
    {!noProfileKey && (profileKeyRequired ? <ParamField header="Profile-Key" type="string" required>
          <a href="/apis/overview#profile-key-format">Profile Key</a> of a User Profile.
          <br />
          <br />
          Format: <code>Profile-Key: PROFILE_KEY</code>
        </ParamField> : <ParamField header="Profile-Key" type="string">
          <a href="/apis/overview#profile-key-format">Profile Key</a> of a User Profile.
          <br />
          <br />
          Format: <code>Profile-Key: PROFILE_KEY</code>
        </ParamField>)}
  </>;

<PlansAvailable plans={["business"]} maxPackRequired={false} />

在你的 Primary Profile 下创建一个新的 profile。User Profile 创建成功后,API 响应将包含与新创建的 profile 关联的 Profile Key。请将该 Profile Key 安全地存储在你的系统中,后续以该用户身份调用 API 时会用到它。

请注意,出于安全考虑,Profile Key 仅在以下两种情况下会被返回:

1. User Profile 创建时:创建新的 User Profile 时。
2. 在 Ayrshare 控制台中:你可以在 Ayrshare 控制台中查看每个 profile 的 Profile Key。切换到该 User Profile,然后进入 Profile Key 页面。

我们建议你将 Profile Key 安全地存储在你的系统中。

## 管理社交网络

使用 disableSocial 字段来管理(添加/移除)展示的社交网络。更多信息请参见[管理社交账户](/apis/profiles/overview#enable-or-disable-social-networks)。

## 管理活跃的 User Profile

请参见此处,查看关于[管理活跃 User Profile](/multiple-users/manage-user-profiles#managing-active-user-profiles) 的建议。

## 重要的安全注意事项

<Warning>
  <ul className="custom-bullets">
    <li>请勿公开分享 Profile Key,或将其暴露在客户端代码或公共代码仓库中。</li>
    <li>Profile Key 是用于对 User Profile 访问进行身份验证与授权的敏感凭据。</li>
    <li>务必将 Profile Key 安全地存储在你的系统中,并设置适当的访问控制,以维护用户数据的完整性与保密性。</li>
    <li>出于安全考虑,无法通过 API 再次获取 Profile Key。不过你可以从[控制台](/multiple-users/manage-user-profiles#get-the-profile-key)中获取。</li>
    <li>同时也应保存 `refId`,以便将 profile 与端点返回结果关联起来。</li>
  </ul>
</Warning>

## Header 参数

<HeaderAPI noProfileKey />

## Body 参数

<ParamField body="title" type="string" required>
  新 profile 的标题。必须唯一。该标题将显示在社交账户关联页面上。
</ParamField>

<ParamField body="messagingActive" type="boolean" default={false}>
  设为 true 可为该 user profile 启用私信 (DM) 功能。必须先在你的 Ayrshare 账户中启用私信功能。
</ParamField>

<ParamField body="hideTopHeader" type="boolean" default={false}>
  在社交账户关联页面上隐藏顶部标题栏。
</ParamField>

<ParamField body="hideLogo" type="boolean" default={false}>
  仅在该 user profile 的社交账户关联页面上隐藏公司 logo。其他 profile 上的账户级 logo 不受影响。适用于对特定合作伙伴 profile 进行白标处理,同时保留其余 profile 的品牌标识。
</ParamField>

<ParamField body="topHeader" type="string">
  更改社交账户关联页面的标题栏。若未设置,则显示:"Social Accounts for "title"",其中 "title" 为 profile 的标题。
</ParamField>

<ParamField body="disableSocial" type="array">
  为该 user profile 禁用的社交网络数组。Primary Profile 上禁用的社交网络列表优先生效。

  可用网络:`bluesky`、`facebook`、`gmb`、`instagram`、`linkedin`、`pinterest`、`reddit`、`snapchat`、`telegram`、`threads`、`tiktok`、`twitter` 和 `youtube`。

  更多信息请参见[启用或禁用社交网络](/apis/profiles/overview#enable-or-disable-social-networks)。
</ParamField>

<ParamField body="team" type="boolean" default={false}>
  通过设置 `team: true`,将新的 user profile 创建为一个团队成员。`email` 字段将用于发送邀请邮件。相关要求详见[邀请团队成员](/multiple-users/manage-user-profiles#invite-a-team-member)。
</ParamField>

<ParamField body="email" type="string">
  用于发送团队成员邀请的有效电子邮件地址。当 `team: true` 时必填。
</ParamField>

<ParamField body="subHeader" type="string">
  更改社交账户关联页面的副标题。当前显示为 "Click an icon to link a social network"。设为空字符串可移除。

  请参阅如何修改[帮助链接](/multiple-users/manage-user-profiles#help-links-visible)。
</ParamField>

<ParamField body="tags" type="array">
  使用字符串数组为 user profile 添加标签。这些标签是用于对 user profile 进行有效分类与管理的内部组织工具。
</ParamField>

<RequestExample>
  ```javascript cURL theme={"system"}
  curl \
  -H "Authorization: Bearer API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"title": "ACME Profile"}' \
  -X POST https://api.ayrshare.com/api/profiles
  ```

  ```javascript JavaScript theme={"system"}
  const API_KEY = "API_KEY";

  fetch("https://api.ayrshare.com/api/profiles", {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          "Authorization": `Bearer ${API_KEY}`
        },
        body: JSON.stringify({
          title: "ACME Profile", // required
        }),
      })
        .then((res) => res.json())
        .then((json) => console.log(json))
        .catch(console.error);
  ```

  ```python Python theme={"system"}
  import requests

  payload = {'title': 'ACME Profile'}
  headers = {'Content-Type': 'application/json',
          'Authorization': 'Bearer API_KEY'}

  r = requests.post('https://api.ayrshare.com/api/profiles',
      json=payload,
      headers=headers)

  print(r.json())
  ```

  ```php PHP theme={"system"}
  <?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',
      [
          'headers' => [
              'Content-Type'      => 'application/json',
              'Authorization'     => 'Bearer API_KEY'
          ],
          'title' => ['ACME Profile'],
      ]
  );

  echo json_encode(json_decode($res->getBody()), JSON_PRETTY_PRINT);
  ```

  ```go Go theme={"system"}
  package main

  import (
  	"bytes"
  	"encoding/json"
  	"log"
  	"net/http"
  )

  func main() {
  	message := map[string]interface{}{
  		"title": "ACME Profile"
  	}

  	bytesRepresentation, err := json.Marshal(message)
  	if err != nil {
  		log.Fatalln(err)
  	}

  	req, _ := http.NewRequest("POST", "https://api.ayrshare.com/api/profiles",
  		bytes.NewBuffer(bytesRepresentation))

  	req.Header.Add("Content-Type", "application/json; charset=UTF-8")
  	req.Header.Add("Authorization", "Bearer API_KEY")

  	res, err := http.DefaultClient.Do(req)
  	if err != nil {
  		log.Fatal("Error:", err)
  	}

  	res.Body.Close()
  }
  ```

  ```csharp C# theme={"system"}
  using System;
  using System.Net.Http;
  using System.Text;
  using System.Threading.Tasks;

  namespace CreateProfilePOSTRequest_csharp 
  {
    class CreateProfile
    {
        static async Task Main(string[] args)
        {
            string API_KEY = "API_KEY";
            string url = "https://api.ayrshare.com/api/profiles";
            string json = "{\"title\": \"ACME Profile\"}";

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Add("Authorization", "Bearer " + API_KEY);

                try
                {
                    var content = new StringContent(json, 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($"Error: {e.Message}");
                }
            }
        }
    }
  }
  ```
</RequestExample>

<ResponseExample>
  ```json 200: Success theme={"system"}
  {
      "status": "success",
      "title": "Digg It",
      "refId": "140b8709bd6ade099b242d895e268fb886130c53",
      "profileKey": "7TVRLEZ-24A43C0-NJW0Z82-F11984N",
      "messagingActive": true // true if messaging for this user profile is active
  }
  ```

  ```json 400: Profile Title Already Exists theme={"system"}
  {
    "action": "create",
    "status": "error",
    "code": 146,
    "message": "Profile title already exists."
  }
  ```
</ResponseExample>
