LoginSignup
1
2

More than 1 year has passed since last update.

qiita apiを叩く

Last updated at Posted at 2022-01-06

概要

javascriptで、qiita apiを叩いてみた。
authenticated_userをgetしてみた。

サンプルコード

var src = document.getElementById('src');
var out = document.getElementById('out');
var endpoint = "https://qiita.com/api/v2/authenticated_user";
function run() {
	var token = src.value;
	//alert(token);
	var xhr = new XMLHttpRequest();
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4 && xhr.status == 200)
		{
			out.value = xhr.responseText;
		}
		else
		{
			//alert(xhr.readyState);
			//alert(xhr.status);
		}
	};
	xhr.open("GET", endpoint, true);
	xhr.setRequestHeader('Authorization', 'Bearer ' + token);
	xhr.send();
	//alert("ok");
}

成果物

以上。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2