I am trying to post a tweet with geo data (latitude and longitude) using the Twitter API v2.0, but I am getting the error message "Invalid Request: One or more parameters to your request was invalid".
Based on the official documentation, I can successfully post simple tweets such as the following (this question is language-agnostic and can be reproduced by forking the Twitter's Public Workspace on Postman):
{
"text": "Hello World!"
}
However, when I add the parameter geo
(see example below), I get the following response:
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]
}
}
Here is the error:
{
"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"
}
After checking the OpenAPI metadata, I noticed the TweetCreateRequest
schema only contains the propertyplace_id
under the attribute geo
.
In summary, how to format the payload properly to include the geo
object in the tweet?