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

使用Twitter API v2获取用户信息遇client-not-enrolled错误求助

问题:调用Twitter API v2时出现"client-not-enrolled"错误

原本通过James Mallison的TwitterAPIExchange调用Twitter API 1.1获取指定用户最新推文的页面,上周起无法正常工作。改用Abraham\TwitterOAuth调用API v2请求用户信息时,持续收到"client-not-enrolled"错误。使用的是免费版API,不确定是权限限制还是操作有误,附上代码及错误结果。

代码示例

$connection = new TwitterOAuth($consumer_key, $consumer_secret, $access_token, $access_token_secret, $bearer_token);
$connection->setApiVersion('2');
$response = $connection->get('users', ['ids' => ****]);
print_r($response);

返回的错误结果

stdClass Object
(
    [client_id] => ******
    [detail] => When authenticating requests to the Twitter API v2 endpoints, you must use keys and tokens from a Twitter developer App that is attached to a Project. You can create a project via the developer portal.
    [title] => Client Forbidden
    [required_enrollment] => Appropriate Level of API Access
    [reason] => client-not-enrolled
    [type] => https://api.twitter.com/2/problems/client-forbidden
)

解决办法

  • API v2强制要求所有调用的App必须关联到一个Twitter开发者项目,免费版也不例外,这是触发错误的核心原因。
  • 操作步骤:
    1. 登录Twitter开发者平台,进入「Projects & Apps」板块
    2. 若没有已创建的项目,点击创建新项目,按引导完成基础设置
    3. 将你当前使用的App绑定到这个新项目中
  • 确认代码中使用的所有密钥(consumer_key、consumer_secret、access_token等)均来自已关联项目的App,避免使用未绑定项目的旧密钥
  • 免费版API可正常调用/users端点,绑定项目后即可解决该错误

内容的提问来源于stack exchange,提问作者tmtsantos

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.15 11:54:54