SYNCER

SYNCER

GET users/search - ユーザーを検索する

9件

公開日:

users/search(GETメソッド)は、ユーザーをキーワードから検索するエンドポイントです。

GET users/search
GET users/search
Twitterの公式リファレンス(英語)。users/searchに関する説明があります。

リソース

エンドポイント

GET https://api.twitter.com/1.1/users/search.json

条件

項目ユーザー認証アプリケーション認証
利用×
パーミッションRead-
レートリミット900 / 15min-

パラメータ

q

指定例: あらゆ

検索キーワード。

page

指定例: 2

何ページ目を取得するか。

count

指定例: 10

結果の数。120の間で指定する。

include_entities

指定例: true

ツイートオブジェクト内のentitiesプロパティを含めるか否か。

レスポンス

アクセストークン(OAuth1.0)でリクエストをした場合の例です。

リクエストURL

https://api.twitter.com/1.1/users/search.json?q=%E3%81%82%E3%82%89%E3%82%86&page=1&count=3&include_entities=true

リクエストヘッダー

Authorization: OAuth count=3,include_entities=true,oauth_consumer_key=:consumer_key,oauth_nonce=0.04966200+1484732280,oauth_signature_method=HMAC-SHA1,oauth_timestamp=1484732280,oauth_token=:access_token,oauth_version=1.0,page=1,q=%E3%81%82%E3%82%89%E3%82%86,oauth_signature=X58ulH7qLW4WDn%2FH04gGn4f434E%3D

レスポンスボディ (JSON)

JSON

[{"id":1528352858,"id_str":"1528352858","name":"\u3042\u3089\u3086","screen_name":"arayutw","location":"\u6771\u4eac\u90fd\u8db3\u7acb\u533a","description":"SYNCER\u3068\u3044\u3046\u30b5\u30a4\u30c8\u3092\u904b\u7528\u3057\u3066\u3044\u307e\u3059\u3002\u63b2\u793a\u677f\u2192 https:\/\/t.co\/OAIDbACF3N","url":"https:\/\/t.co\/lW3GYq8sQl","entities":{"url":{"urls":[{"url":"https:\/\/t.co\/lW3GYq8sQl","expanded_url":"https:\/\/syncer.jp\/","display_url":"syncer.jp","indices":[0,23]}]},"description":{"urls":[{"url":"https:\/\/t.co\/OAIDbACF3N","expanded_url":"https:\/\/forum.syncer.jp\/","display_url":"forum.syncer.jp","indices":[26,49]}]}},"protected":false,"followers_count":1417,"friends_count":563,"listed_count":114,"created_at":"Tue Jun 18 17:28:51 +0000 2013","favourites_count":4455,"utc_offset":32400,"time_zone":"Asia\/Tokyo","geo_enabled":true,"verified":false,"statuses_count":34824,"lang":"ja","status":{"created_at":"Wed Jan 18 09:36:48 +0000 2017","id":821652553255571458,"id_str":"821652553255571458","text":"murashun.jp\u304c\u4eba\u6c17\u3002","truncated":false,"entities":{"hashtags":[],"symbols":[],"user_mentions":[],"urls":[]},"source":"\u003ca href=\"http:\/\/twitter.com\" rel=\"nofollow\"\u003eTwitter Web Client\u003c\/a\u003e","in_reply_to_status_id":821652327794966530,"in_reply_to_status_id_str":"821652327794966530","in_reply_to_user_id":1528352858,"in_reply_to_user_id_str":"1528352858","in_reply_to_screen_name":"arayutw","geo":null,"coordinates":null,"place":null,"contributors":null,"is_quote_status":false,"retweet_count":0,"favorite_count":0,"favorited":false,"retweeted":false,"lang":"ja"},"contributors_enabled":false,"is_translator":false,"is_translation_enabled":true,"profile_background_color":"2660A1","profile_background_image_url":"http:\/\/pbs.twimg.com\/profile_background_images\/632205394824183808\/FIL3S4z4.png","profile_background_image_url_https":"https:\/\/pbs.twimg.com\/profile_background_images\/632205394824183808\/FIL3S4z4.png","profile_background_tile":false,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/631038167416619008\/7xfGAEwp_normal.png","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/631038167416619008\/7xfGAEwp_normal.png","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/1528352858\/1484730634","profile_link_color":"D36015","profile_sidebar_border_color":"F2E195","profile_sidebar_fill_color":"FFF7CC","profile_text_color":"0C3E53","profile_use_background_image":false,"has_extended_profile":false,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false,"translator_type":"regular"},{"id":3138166249,"id_str":"3138166249","name":"\u3042\u3089\u3086\u4e8c\u30c0\u30c3\uff01","screen_name":"akumu_tann0721","location":"\u5f3e\u5e55\u4f1a","description":"\u200d\u305d\u3046\u3060\u5927\u9ebb\u3067\u3082\u5438\u3063\u3066\u30a8\u30c3\u30c1\u3057\u3088","url":"https:\/\/t.co\/7A5tgk6H6V","entities":{"url":{"urls":[{"url":"https:\/\/t.co\/7A5tgk6H6V","expanded_url":"http:\/\/xn--u9j680gfj9a.com","display_url":"\u81a3\u306e\u4e2d.com","indices":[0,23]}]},"description":{"urls":[]}},"protected":false,"followers_count":2163,"friends_count":87,"listed_count":27,"created_at":"Fri Apr 03 23:21:37 +0000 2015","favourites_count":50041,"utc_offset":null,"time_zone":null,"geo_enabled":false,"verified":false,"statuses_count":40034,"lang":"ja","status":{"created_at":"Wed Jan 18 08:46:06 +0000 2017","id":821639793306206209,"id_str":"821639793306206209","text":"@ruimonster \u306a\u3093\u3084\u3066w","truncated":false,"entities":{"hashtags":[],"symbols":[],"user_mentions":[{"screen_name":"ruimonster","name":"RuI","id":999220609,"id_str":"999220609","indices":[0,11]}],"urls":[]},"source":"\u003ca href=\"http:\/\/twitter.com\/download\/iphone\" rel=\"nofollow\"\u003eTwitter for iPhone\u003c\/a\u003e","in_reply_to_status_id":821639643758292992,"in_reply_to_status_id_str":"821639643758292992","in_reply_to_user_id":999220609,"in_reply_to_user_id_str":"999220609","in_reply_to_screen_name":"ruimonster","geo":null,"coordinates":null,"place":null,"contributors":null,"is_quote_status":false,"retweet_count":0,"favorite_count":0,"favorited":false,"retweeted":false,"lang":"ja"},"contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"C0DEED","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/820354738013114369\/cPedB3DY_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/820354738013114369\/cPedB3DY_normal.jpg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/3138166249\/1466047818","profile_link_color":"1DA1F2","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"has_extended_profile":false,"default_profile":true,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false,"translator_type":"none"},{"id":2703466668,"id_str":"2703466668","name":"\u3042\u3089\u3086\u6c0f","screen_name":"liilU4","location":"\u5343\u8449","description":"rob(@___rob____ )\u3068\u3044\u3046\u30d0\u30f3\u30c9\u3067\u304d\u306e\u3053\u3084\u3063\u3066\u307e\u3059\u3002\u8ca7\u4e4f\u30ae\u30bf\u30ea\u30b9\u30c8\u5343\u8449\u4ee3\u8868","url":"https:\/\/t.co\/RyBgHkbG5X","entities":{"url":{"urls":[{"url":"https:\/\/t.co\/RyBgHkbG5X","expanded_url":"http:\/\/Instagram.com\/u4__yh","display_url":"Instagram.com\/u4__yh","indices":[0,23]}]},"description":{"urls":[]}},"protected":false,"followers_count":6661,"friends_count":1402,"listed_count":73,"created_at":"Sun Aug 03 07:12:23 +0000 2014","favourites_count":45396,"utc_offset":-28800,"time_zone":"Pacific Time (US & Canada)","geo_enabled":false,"verified":false,"statuses_count":3237,"lang":"ja","status":{"created_at":"Wed Jan 18 03:49:35 +0000 2017","id":821565172745584640,"id_str":"821565172745584640","text":"\u3053\u306e\u8a00\u8449\u5b9a\u671f\u7684\u306b\u6d6e\u304b\u3093\u3067\u304f\u308b","truncated":false,"entities":{"hashtags":[],"symbols":[],"user_mentions":[],"urls":[]},"source":"\u003ca href=\"http:\/\/twitter.com\/download\/iphone\" rel=\"nofollow\"\u003eTwitter for iPhone\u003c\/a\u003e","in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"geo":null,"coordinates":null,"place":null,"contributors":null,"is_quote_status":false,"retweet_count":0,"favorite_count":6,"favorited":false,"retweeted":false,"lang":"ja"},"contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"C0DEED","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/814141171781890048\/c-UXX8v3_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/814141171781890048\/c-UXX8v3_normal.jpg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/2703466668\/1482935567","profile_link_color":"1DA1F2","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"has_extended_profile":false,"default_profile":true,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false,"translator_type":"none"}]

レスポンスヘッダー

HTTP/1.1 200 OK
cache-control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0
content-disposition: attachment; filename=json.json
content-length: 7799
content-type: application/json;charset=utf-8
date: Wed, 18 Jan 2017 09:38:00 GMT
expires: Tue, 31 Mar 1981 05:00:00 GMT
last-modified: Wed, 18 Jan 2017 09:38:00 GMT
pragma: no-cache
server: tsa_m
set-cookie: lang=ja; Path=/
set-cookie: guest_id=v1%3A148473228014833648; Domain=.twitter.com; Path=/; Expires=Fri, 18-Jan-2019 09:38:00 UTC
status: 200 OK
strict-transport-security: max-age=631138519
x-access-level: read
x-connection-hash: 6c4ab42c3fb48c52ae0d2c018eaae16c
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-rate-limit-limit: 900
x-rate-limit-remaining: 899
x-rate-limit-reset: 1484733180
x-response-time: 263
x-transaction: 003f2d32005c1f51
x-twitter-response-tags: BouncerCompliant
x-xss-protection: 1; mode=block

デモ

users/searchのリクエストを試すことができます。ユーザー認証のデモを試す場合は、アプリケーション(読取権限)の連携を許可する必要があります。利用後、お手数ですが連携の解除をお願いします。連携を解除し忘れたとしても、当アプリケーションが許可なくデータにアクセスすることはありません。

q

page

count

include_entities

/

認証方法 (ユーザー認証のみ)

/

サンプルコード

users/searchのエンドポイントを利用するためのサンプルプログラムです。各種トークンの情報をセットしてからPHPで起動して下さい。リクエストに成功すると、$jsonという変数に目的のデータが代入されます。このデータを整形するなり保存するなり、活用して下さい。

アクセストークン

PHP (OAuth1.0)

<?php
/**************************************************

	[GET users/lookup]のお試しプログラム

	認証方式: ベアラートークン

	配布: SYNCER
	公式ドキュメント: https://dev.twitter.com/rest/reference/get/users/lookup
	日本語解説ページ: https://syncer.jp/Web/API/Twitter/REST_API/GET/users/lookup/

**************************************************/

	// 設定
	$bearer_token = '' ;	// ベアラートークン
	$request_url = 'https://api.twitter.com/1.1/users/lookup.json' ;		// エンドポイント

	// パラメータ (オプション)
	$params = array(
		"user_id" => "1528352858,2905085521",
//		"screen_name" => "arayutw,syncerjp",
//		"include_entities" => "true",
	) ;

	// パラメータがある場合
	if( $params ) {
		$request_url .= '?' . http_build_query( $params ) ;
	}

	// リクエスト用のコンテキスト
	$context = array(
		'http' => array(
			'method' => 'GET' , // リクエストメソッド
			'header' => array(			  // ヘッダー
				'Authorization: Bearer ' . $bearer_token ,
			) ,
		) ,
	) ;

	// cURLを使ってリクエスト
	$curl = curl_init() ;
	curl_setopt( $curl , CURLOPT_URL , $request_url ) ;
	curl_setopt( $curl , CURLOPT_HEADER, 1 ) ; 
	curl_setopt( $curl , CURLOPT_CUSTOMREQUEST , $context['http']['method'] ) ;			// メソッド
	curl_setopt( $curl , CURLOPT_SSL_VERIFYPEER , false ) ;								// 証明書の検証を行わない
	curl_setopt( $curl , CURLOPT_RETURNTRANSFER , true ) ;								// curl_execの結果を文字列で返す
	curl_setopt( $curl , CURLOPT_HTTPHEADER , $context['http']['header'] ) ;			// ヘッダー
	curl_setopt( $curl , CURLOPT_TIMEOUT , 5 ) ;										// タイムアウトの秒数
	$res1 = curl_exec( $curl ) ;
	$res2 = curl_getinfo( $curl ) ;
	curl_close( $curl ) ;

	// 取得したデータ
	$json = substr( $res1, $res2['header_size'] ) ;				// 取得したデータ(JSONなど)
	$header = substr( $res1, 0, $res2['header_size'] ) ;		// レスポンスヘッダー (検証に利用したい場合にどうぞ)

	// [cURL]ではなく、[file_get_contents()]を使うには下記の通りです…
	// $json = @file_get_contents( $request_url , false , stream_context_create( $context ) ) ;

	// JSONをオブジェクトに変換 (処理をする場合)
//	$obj = json_decode( $json ) ;

	// HTML用
	$html = '' ;

	// タイトル
	$html .= '<h1 style="text-align:center; border-bottom:1px solid #555; padding-bottom:12px; margin-bottom:48px; color:#D36015;">GET users/lookup</h1>' ;

	// 検証用
	$html .= '<h2>取得したデータ</h2>' ;
	$html .= '<p>下記のデータを取得できました。</p>' ;
	$html .= 	'<h3>ボディ(JSON)</h3>' ;
	$html .= 	'<p><textarea style="width:80%" rows="8">' . $json . '</textarea></p>' ;
	$html .= 	'<h3>レスポンスヘッダー</h3>' ;
	$html .= 	'<p><textarea style="width:80%" rows="8">' . $header . '</textarea></p>' ;

	// 検証用
	$html .= '<h2>リクエストしたデータ</h2>' ;
	$html .= '<p>下記内容でリクエストをしました。</p>' ;
	$html .= 	'<h3>URL</h3>' ;
	$html .= 	'<p><textarea style="width:80%" rows="8">' . $context['http']['method'] . ' ' . $request_url . '</textarea></p>' ;
	$html .= 	'<h3>ヘッダー</h3>' ;
	$html .= 	'<p><textarea style="width:80%" rows="8">' . implode( "\r\n" , $context['http']['header'] ) . '</textarea></p>' ;

	// フッター
	$html .= '<small style="display:block; border-top:1px solid #555; padding-top:12px; margin-top:72px; text-align:center; font-weight:700;">プログラムの説明: <a href="https://syncer.jp/Web/API/Twitter/REST_API/GET/users/lookup/" target="_blank">SYNCER</a></small>' ;

	// 出力 (本稼働時はHTMLのヘッダー、フッターを付けよう)
	echo $html ;