Back to Collection Items
#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
#include <C_CkHttpResponse.h>
void ChilkatSample(void)
{
HCkHttp http;
BOOL success;
HCkJsonObject json;
HCkHttpResponse resp;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttp_Create();
// 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"
// }
json = CkJsonObject_Create();
CkJsonObject_UpdateString(json,"tweet_id","1503863301276827651");
// Adds the "Authorization: Bearer <access_token>" header.
CkHttp_putAuthToken(http,"<access_token>");
resp = CkHttp_PostJson3(http,"https://api.twitter.com/2/users/:id/bookmarks","application/json",json);
if (CkHttp_getLastMethodSuccess(http) == FALSE) {
printf("%s\n",CkHttp_lastErrorText(http));
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
return;
}
printf("%d\n",CkHttpResponse_getStatusCode(resp));
printf("%s\n",CkHttpResponse_bodyStr(resp));
CkHttpResponse_Dispose(resp);
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
}
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": [
]
}