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

如何使用Twitter API v2.0正确发布带地理数据的推文?

Content-Type: application/json
Accept: application/json

请求体:
```json
{
    "text":"Testing tweets with geo-location.",
    "geo": {
        "type":"Point",
        "coordinates":[40.74118764,-73.9998279]
    }
}

错误响应:

{
    "errors": [
        {
            "parameters": {
                "$.geo": [
                    "{\"type\":\"Point\",\"coordinates\":[40.74118764,-73.9998279]}"
                ]
            },
            "message": "$.geo.type: is not defined in the schema and the schema does not allow additional properties"
        },
        {
            "parameters": {
                "$.geo": [
                    "{\"type\":\"Point\",\"coordinates\":[40.74118764,-73.9998279]}"
                ]
            },
            "message": "$.geo.coordinates: is not defined in the schema and the schema does not allow additional properties"
        }
    ],
    "title": "Invalid Request",
    "detail": "One or more parameters to your request was invalid.",
    "type": "https://api.twitter.com/2/problems/invalid-request"
}

查看OpenAPI元数据后发现,TweetCreateRequest schema的geo属性仅包含place_id字段,请问如何正确格式化请求payload来在推文中包含地理信息?

正确的请求格式

Twitter API v2.0的推文创建接口(POST /2/tweets)不支持直接传入经纬度坐标,geo对象仅接受place_id参数。要给推文添加地理信息,需先获取目标位置对应的place_id,再填入请求体的geo字段中。

操作步骤:

  • 获取place_id:调用GET /2/places/search接口,传入经纬度等参数搜索目标地点,返回结果中的id即为所需的place_id。
  • 构造推文请求:将获取到的place_id填入请求体,示例如下:
{
    "text": "Testing tweets with geo-location.",
    "geo": {
        "place_id": "替换为实际的place_id"
    }
}

注意:API v2.0的推文创建接口不支持直接绑定经纬度,必须通过place_id关联平台已收录的地点数据。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.27 08:32:36