Skip to content

Commit a46d427

Browse files
committed
Include long-form tweet fields in read shortcut
1 parent 99a7848 commit a46d427

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

api/shortcuts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func ReadPost(client Client, postID string, opts RequestOptions) (json.RawMessag
164164
postID = ResolvePostID(postID)
165165

166166
opts.Method = "GET"
167-
opts.Endpoint = fmt.Sprintf("/2/tweets/%s?tweet.fields=created_at,public_metrics,conversation_id,in_reply_to_user_id,referenced_tweets,entities,attachments&expansions=author_id,referenced_tweets.id&user.fields=username,name,verified", postID)
167+
opts.Endpoint = fmt.Sprintf("/2/tweets/%s?tweet.fields=created_at,public_metrics,conversation_id,in_reply_to_user_id,referenced_tweets,entities,attachments,note_tweet,article&expansions=author_id,referenced_tweets.id&user.fields=username,name,verified", postID)
168168
opts.Data = ""
169169

170170
return client.SendRequest(opts)

api/shortcuts_test.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,14 @@ func setupShortcutServer() *httptest.Server {
8888

8989
// GET /2/tweets/:id — read post
9090
case strings.HasPrefix(r.URL.Path, "/2/tweets/") && r.Method == "GET":
91+
fields := r.URL.Query().Get("tweet.fields")
92+
if !strings.Contains(fields, "note_tweet") || !strings.Contains(fields, "article") {
93+
w.WriteHeader(http.StatusBadRequest)
94+
w.Write([]byte(`{"errors":[{"message":"missing long-form tweet fields"}]}`))
95+
return
96+
}
9197
w.WriteHeader(http.StatusOK)
92-
w.Write([]byte(`{"data":{"id":"123","text":"existing post","public_metrics":{"like_count":5}}}`))
98+
w.Write([]byte(`{"data":{"id":"123","text":"existing post","note_tweet":{"text":"full long-form post"},"public_metrics":{"like_count":5}}}`))
9399

94100
// GET /2/users/me
95101
case r.URL.Path == "/2/users/me" && r.Method == "GET":
@@ -216,12 +222,16 @@ func TestReadPost(t *testing.T) {
216222

217223
var result struct {
218224
Data struct {
219-
ID string `json:"id"`
220-
Text string `json:"text"`
225+
ID string `json:"id"`
226+
Text string `json:"text"`
227+
NoteTweet struct {
228+
Text string `json:"text"`
229+
} `json:"note_tweet"`
221230
} `json:"data"`
222231
}
223232
require.NoError(t, json.Unmarshal(resp, &result))
224233
assert.Equal(t, "123", result.Data.ID)
234+
assert.Equal(t, "full long-form post", result.Data.NoteTweet.Text)
225235
}
226236

227237
// ---- SearchPosts ----

0 commit comments

Comments
 (0)