Chilkat Online Tools

autoit / Twitter API v2 / Bookmark a Tweet

Back to Collection Items

; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.

$oHttp = ObjCreate("Chilkat_9_5_0.Http")
Local $bSuccess

; Use this online tool to generate code from sample JSON: Generate Code to Create JSON

; The following JSON is sent in the request body.

; {
;   "tweet_id": "1503863301276827651"
; }

$oJson = ObjCreate("Chilkat_9_5_0.JsonObject")
$oJson.UpdateString("tweet_id","1503863301276827651")

; Adds the "Authorization: Bearer <access_token>" header.
$oHttp.AuthToken = "<access_token>"

Local $oResp = $oHttp.PostJson3("https://api.twitter.com/2/users/:id/bookmarks","application/json",$oJson)
If ($oHttp.LastMethodSuccess = False) Then
    ConsoleWrite($oHttp.LastErrorText & @CRLF)
    Exit
EndIf

ConsoleWrite($oResp.StatusCode & @CRLF)
ConsoleWrite($oResp.BodyStr & @CRLF)

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-d '{
    "tweet_id": "1503863301276827651"
}'
https://api.twitter.com/2/users/:id/bookmarks

Postman Collection Item JSON

{
  "name": "Bookmark a Tweet",
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "exec": [
          "// This script extracts the ID of the authenticating user, so you do not have to pass it yourself.",
          "if (!pm.environment.get('access_token') || !pm.request.url.path.includes(':id')) {",
          "    return;",
          "}",
          "",
          "const [userId] = pm.environment.get('access_token').split('-');",
          "",
          "if (!userId) {",
          "    return;",
          "}",
          "",
          "const userIdIndex = pm.request.url.path.indexOf(':id');",
          "pm.request.url.path[userIdIndex] = userId;"
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "auth": {
      "type": "oauth2",
      "oauth2": [
        {
          "key": "state",
          "value": "",
          "type": "string"
        },
        {
          "key": "scope",
          "value": "",
          "type": "string"
        },
        {
          "key": "accessTokenUrl",
          "value": "",
          "type": "string"
        },
        {
          "key": "authUrl",
          "value": "",
          "type": "string"
        },
        {
          "key": "tokenName",
          "value": "bookmarks",
          "type": "string"
        },
        {
          "key": "redirect_uri",
          "value": "",
          "type": "string"
        },
        {
          "key": "clientId",
          "value": "",
          "type": "string"
        },
        {
          "key": "grant_type",
          "value": "authorization_code_with_pkce",
          "type": "string"
        },
        {
          "key": "addTokenTo",
          "value": "header",
          "type": "string"
        }
      ]
    },
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"tweet_id\": \"1503863301276827651\"\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "https://api.twitter.com/2/users/:id/bookmarks",
      "protocol": "https",
      "host": [
        "api",
        "twitter",
        "com"
      ],
      "path": [
        "2",
        "users",
        ":id",
        "bookmarks"
      ],
      "variable": [
        {
          "key": "id",
          "value": "",
          "description": "The ID of the user who wishes to like a Tweet. The ID must belong to the authenticating user.\n"
        }
      ]
    },
    "description": "Allows an authenticated user to like a Tweet.\n\nFor full details, see the [API reference](https://developer.twitter.com/en/docs/twitter-api/tweets/bookmarks/api-reference/post-users-user_id-bookmarks) for this endpoint.\n\n[Sign up](https://t.co/signup) for the Twitter API"
  },
  "response": [
  ]
}