메인 콘텐츠로 건너뛰기

인용 게시물 조회 엔드포인트 시작하기

이 빠른 시작 가이드는 Postman을 사용하여 지정한 필드 세트와 함께 인용 게시물 조회 엔드포인트에 첫 요청을 보내는 방법을 안내합니다. 다양한 언어의 샘플 코드를 확인하려면 X API v2 샘플 코드 GitHub 리포지토리를 방문하세요. 

사전 준비 사항

이 가이드를 완료하려면 요청 인증에 필요한 키와 토큰 세트가 있어야 합니다. 다음 단계를 따라 키와 토큰을 생성할 수 있습니다.
  • 개발자 계정을 신청하고 승인을 받습니다.
  • 개발자 포털에서 Project와 연결된 developer App을 생성합니다.
  • App의 “Keys and tokens” 페이지로 이동해 필요한 자격 증명을 생성합니다. 모든 자격 증명은 안전한 위치에 보관하세요.
인용 게시물(Quote Tweets) 조회 요청 빌드 단계 1단계: 도구 또는 라이브러리 시작하기 이 엔드포인트에 요청을 보내는 데 사용할 수 있는 도구, 코드 예제, 라이브러리가 여러 가지 있으나, 여기서는 과정을 단순화하기 위해 Postman을 사용하겠습니다. X API v2 Postman 컬렉션을 환경에 로드하려면 다음 버튼을 클릭하세요. Postman에 X API v2 컬렉션이 로드되면 timeline 폴더로 이동하여 “Quote Tweets by ID” 요청을 찾습니다. 2단계: 요청 인증 X API에 올바르게 요청하려면 권한이 있는지 검증해야 합니다. 이 엔드포인트에서는 OAuth 2.0 App-Only, OAuth 2.0 Authorization Code with PKCE, 또는 OAuth 1.0a 사용자 컨텍스트 인증 방법 중 하나로 요청을 인증해야 합니다. 단순화를 위해 이 요청에서는 OAuth 2.0 App-Only를 사용하겠지만, 비공개 지표나 게시물을 요청하려면 다른 인증 방법 중 하나를 사용해야 합니다. Postman에 키와 토큰, 특히 App Access Token (App-only Bearer Token이라고도 함)을 추가해야 합니다. Postman 오른쪽 상단에서 “X API v2” 환경을 선택한 뒤 “initial value”와 “current value” 필드에 키와 토큰을 추가하세요(환경 드롭다운 옆 눈 아이콘 클릭). 올바르게 설정했다면 이 변수는 요청의 Authorization 탭에 자동으로 반영됩니다. 3단계: 인용 게시물(Quote Tweets)을 조회할 게시물 지정 요청에서 게시물 ID를 전달해 인용 게시물을 조회할 대상 게시물을 지정해야 합니다. 이 예제에서 사용할 게시물 ID는 1409931481552543749입니다. Postman에서 “Params” 탭으로 이동하여 이 게시물 ID를 id 매개변수의 “Value” 열에 입력합니다.
KeyValue
id1409931481552543749
4단계: 조회할 필드 지정 3단계를 완료한 후 “Send” 버튼을 클릭하면 응답에 기본 Post object 필드인 id, text, edit_history_tweet_ids가 반환됩니다. 추가 필드를 받으려면 요청에서 fields 및/또는 expansions 매개변수를 사용해 해당 필드를 지정해야 합니다. 이 연습에서는 서로 다른 객체에서 다음 세 가지 추가 필드를 요청합니다.
  1. 기본 트윗 객체의 추가 tweet.created_at 필드
  2. 반환된 게시물의 작성자 사용자 객체 기본 필드: id, name, username
  3. 관련 사용자 객체의 추가 user.created_at 필드  
Postman에서 “Params” 탭으로 이동하여 “Query Params” 표에 다음 key:value 쌍을 추가합니다:
반환 필드
tweet.fieldscreated_attweets.created_at
expansionsauthor_idincludes.users.id, includes.users.name, includes.users.username
user.fieldscreated_atincludes.users.created_at
이제 “Send” 버튼 옆에 다음 URL이 표시되어야 합니다: https://api.x.com/2/tweets/:id/quote_tweets?expansions=author_id&tweet.fields=created_at&user.fields=created_at 참고: Postman에서는 URL 필드의 경로 매개변수 :id가 id 파라미터 필드에 입력한 값으로 자동 업데이트되지 않습니다. 따라서 위의 URL에는 1409931481552543749가 아니라 :id가 포함됩니다. 5단계: 요청을 보내고 응답을 확인하세요 모든 설정을 마쳤다면 “Send” 버튼을 눌러 요청을 보내면 다음과 같은 응답을 받게 됩니다:
{
 "data": [
   {
     "created_at": "2022-02-22T04:31:34.000Z",
     "text": "RT @chris_bail: Twitter has created an entire course (with videos, code, and other materials) to help researchers learn how to collect data…",
     "author_id": "29757971",
     "id": "1495979553889697792"
   },
   {
     "created_at": "2022-01-26T17:07:43.000Z",
     "text": "RT @suhemparack: Super excited to share our course on Getting started with the #TwitterAPI v2 for academic research\n\nIf you know students w…",
     "author_id": "241588187",
     "id": "1486385372401737728"
   },
   {
     "created_at": "2022-01-11T17:28:04.000Z",
     "text": "RT @suhemparack: Super excited to share our course on Getting started with the #TwitterAPI v2 for academic research\n\nIf you know students w…",
     "author_id": "24961055",
     "id": "1480954678447857669"
   },
   {
     "created_at": "2022-01-10T20:34:46.000Z",
     "text": "RT @suhemparack: Super excited to share our course on Getting started with the #TwitterAPI v2 for academic research\n\nIf you know students w…",
     "author_id": "1441574419789324291",
     "id": "1480639272721940486"
   },
   {
     "created_at": "2021-12-16T22:55:24.000Z",
     "text": "RT @chris_bail: Twitter has created an entire course (with videos, code, and other materials) to help researchers learn how to collect data…",
     "author_id": "1623598771",
     "id": "1471614967207976961"
   },
   {
     "created_at": "2021-12-13T15:59:55.000Z",
     "text": "RT @suhemparack: Super excited to share our course on Getting started with the #TwitterAPI v2 for academic research\n\nIf you know students w…",
     "author_id": "1506401233",
     "id": "1470423243513372679"
   },
   {
     "created_at": "2021-12-10T02:02:45.000Z",
     "text": "RT @suhemparack: Super excited to share our course on Getting started with the #TwitterAPI v2 for academic research\n\nIf you know students w…",
     "author_id": "40103034",
     "id": "1469125403373568001"
   },
   {
     "created_at": "2021-12-08T17:27:54.000Z",
     "text": "RT @suhemparack: Super excited to share our course on Getting started with the #TwitterAPI v2 for academic research\n\nIf you know students w…",
     "author_id": "1436400156006567936",
     "id": "1468633446935318529"
   },
   {
     "created_at": "2021-09-15T21:40:24.000Z",
     "text": "RT @suhemparack: Super excited to share our course on Getting started with the #TwitterAPI v2 for academic research\n\nIf you know students w…",
     "author_id": "81650379",
     "id": "1438256410417143809"
   },
   {
     "created_at": "2021-08-26T16:45:16.000Z",
     "text": "RT @suhemparack: Super excited to share our course on Getting started with the #TwitterAPI v2 for academic research\n\nIf you know students w…",
     "author_id": "40462535",
     "id": "1430934381829492746"
   }
 ],
 "includes": {
   "users": [
     {
       "username": "j_a_tucker",
       "id": "29757971",
       "name": "Joshua Tucker",
       "created_at": "2009-04-08T16:45:38.000Z"
     },
     {
       "username": "whimchic",
       "id": "241588187",
       "name": "whimchic",
       "created_at": "2011-01-22T16:51:43.000Z"
     },
     {
       "username": "mattbiehl",
       "id": "24961055",
       "name": "Matthias Biehl",
       "created_at": "2009-03-17T21:41:27.000Z"
     },
     {
       "username": "weixinac",
       "id": "1441574419789324291",
       "name": "J",
       "created_at": "2021-09-25T01:25:19.000Z"
     },
     {
       "username": "RSangeleer",
       "id": "1623598771",
       "name": "Richard Sangeleer",
       "created_at": "2013-07-26T18:25:45.000Z"
     },
     {
       "username": "Gulnerman",
       "id": "1506401233",
       "name": "Giz Gulnerman",
       "created_at": "2013-06-11T20:13:40.000Z"
     },
     {
       "username": "efishman123",
       "id": "40103034",
       "name": "Elishema Fishman",
       "created_at": "2009-05-14T22:25:58.000Z"
     },
     {
       "username": "dtcxwz",
       "id": "1436400156006567936",
       "name": "Hüseyin Ateş",
       "created_at": "2021-09-10T18:44:30.000Z"
     },
     {
       "username": "brendaberkelaar",
       "id": "81650379",
       "name": "Dr. Brenda Berkelaar",
       "created_at": "2009-10-11T18:09:16.000Z"
     },
     {
       "username": "misoca",
       "id": "40462535",
       "name": "Michael Soto",
       "created_at": "2009-05-16T13:26:05.000Z"
     }
   ]
 },
 "meta": {
   "result_count": 10,
   "next_token": "avdjwk0udyx6"
 }
}

6단계: 결과 페이지네이션

이전 응답의 하단에는 다음 필드를 포함하는 metadata 객체가 있습니다:
  • results_count
  • next_token
4단계에서 max_results 매개변수를 지정하지 않았기 때문에 기본적으로 게시물 10개만 반환됩니다. 추가 데이터 페이지에 접근하려면 마지막 결과의 next_token 필드 값을 가져와 해당 문자열을 Postman의 params 페이지에서 pagination_token 매개변수의 값으로 추가하고, 나머지 설정은 그대로 유지합니다.
KeyValue
pagination_tokenavdjwk0udyx6
모든 설정을 마쳤다면 “Send”를 다시 클릭하여 다음 페이지의 결과를 받을 수 있습니다. 이 개념을 더 자세히 설명한 페이지네이션 가이드를 마련해 두었습니다.