我正在尝试使用 Twitter API v2.0 发布带有地理数据(纬度和经度)的推文,但我收到错误消息“无效请求:您请求的一个或多个参数无效”。
基于官方文档,我可以成功发布如下简单的推文(这个问题与语言无关,可以通过在 Postman 上分叉 Twitter 的公共工作空间):
{
"text": "Hello World!"
}
但是,当我添加参数
geo
(参见下面的示例)时,我得到以下响应:
POST /2/tweets HTTP/1.1
Host: api.twitter.com
...
Content-Type: application/json
Accept: application/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
模式只包含属性place_id
在属性geo
下。
总而言之,如何正确格式化有效负载以在推文中包含
geo
对象?