You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

开发模式下调用Facebook API创建客户企业失败问题求助

解决Facebook API添加合作伙伴企业时的42004/1752286错误

错误信息

{"error":{"message":"You couldn't create the client business on behalf your client successfully","type":"OAuthException","code":42004,"error_subcode":1752286,"is_transient":false,"error_user_title":"Fail to create business relationship aggregator on behalf of client","error_user_msg":"Business On-Behalf-Of creation fails because the app is in dev mode and the Business On-Behalf-Of creator is not an admin of both client business and partner business."}}

问题核心

你的应用处于开发模式,且发起操作的用户(即accessToken对应的用户)同时不是合作伙伴企业(partnerBusinessId)和客户企业(clientBusinessId)的管理员,导致API权限校验失败。

解决步骤

  • 检查用户角色权限
    登录Facebook商务管理平台,分别查看该用户在两个企业中的角色:

    • 合作伙伴企业:确保用户拥有「管理员(Admin)」权限
    • 客户企业:同样需要用户拥有「管理员(Admin)」权限
      若权限不足,联系对应企业的现有管理员为该用户升级权限。
  • 配置测试用户
    在Facebook开发者后台,将具备双管理员权限的用户添加为应用的测试用户(进入应用的「角色」或「测试用户」页面操作),开发模式下只有测试用户和关联企业管理员能正常调用接口。

  • 验证Access Token有效性
    调用Facebook的token验证接口,确认token的权限和关联用户:

    GET /debug_token?input_token={你的accessToken}&access_token={你的应用access_token}
    

    检查返回结果中是否包含business_management权限,且关联用户ID对应双企业管理员账号。

  • 核对参数正确性
    确认代码中partnerBusinessId和clientBusinessId没有填反,参数错误也会触发权限校验失败。

你的实现代码

private async Task<bool> AddPartnerToBusinessAsync(string partnerBusinessId, string clientBusinessId, string accessToken)
{
    using (var client = new HttpClient())
    {
        var requestUrl = $"https://graph.facebook.com/v15.0/{partnerBusinessId}/managed_businesses";
        var content = new FormUrlEncodedContent(new[]
        {
            new KeyValuePair<string, string>("existing_client_business_id", clientBusinessId),
            new KeyValuePair<string, string>("access_token", accessToken)
        });

        var response = await client.PostAsync(requestUrl, content);

        if (response.IsSuccessStatusCode)
        {
            return true;
        }
        else
        {
            // Log or handle the error
            var errorResponse = await response.Content.ReadAsStringAsync();
            Console.WriteLine($"Facebook API Error: {response.StatusCode} - {errorResponse}");

            // Handle specific errors
            var errorData = JsonConvert.DeserializeObject<dynamic>(errorResponse);
            var errorCode = (int)errorData.error.code;
            var errorSubcode = (int)errorData.error.error_subcode;

            if (errorCode == 42004 && errorSubcode == 1752286)
            {
                Console.WriteLine("Business On-Behalf-Of creation fails because the app is in dev mode and the user is not an admin of both client business and partner business.");
                // Provide additional guidance or steps to the user
            }

            return false;
        }
    }
}

内容的提问来源于stack exchange,提问作者New Developer 2017

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 01:30:55