4

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?

  • I have the same problem. I see the [POST /2/tweets](https://developer.twitter.com/en/docs/twitter-api/tweets/manage-tweets/api-reference/post-tweets) API spec is light on detail, only lists `geo.place_id` attribute as allowed. API v1 allowed sending a tweet with just lat/long and no "place" (what I think we both want). Maybe we need a "place" now? But places may not be available in the V2 API yet per "Geo = coming soon" in the [API V2 endpoint roadmap](https://developer.twitter.com/en/docs/twitter-api/migrate/twitter-api-endpoint-map) – Brad Wehrwein Apr 21 '23 at 21:13
  • I'm unfamiliar with the v1 geo/places APIs. Is it currently possible to create a "place" using older v1 APIs in the new free API v2 accounts setup? – Brad Wehrwein Apr 21 '23 at 21:23

0 Answers0