-
Notifications
You must be signed in to change notification settings - Fork 0
/
jamendo2.html
57 lines (49 loc) · 2.02 KB
/
jamendo2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!DOCTYPE html>
<html>
<head>
<title>Jamendo Web API Example</title>
<script src="https://unpkg.com/tone"></script>
<style>
.disabled {
opacity: 0.5;
pointer-events: none;
}
</style>
</head>
<body>
<h1>Jamendo Web API Example V4</h1>
<button id="authenticateButton" onclick="authenticate()">Authenticate</button>
<p id="authInfo"></p>
<script>
const clientId = '69073f3b'; // Replace with your Jamendo API client ID
const redirectUri = 'https://eliasds.github.io/Binaural-Learning/redirect.html'; // Replace with your redirect URI
const responseType = 'code';
const scope = 'basic';
function authenticate() {
const authUrl = `https://api.jamendo.com/v3.0/oauth/authorize?client_id=${clientId}&redirect_uri=${redirectUri}&response_type=${responseType}&scope=${scope}`;
window.location.href = authUrl;
}
// Check if access token is present in the URL query parameters
const urlParams = new URLSearchParams(window.location.search);
const code = urlParams.get('code');
if (code) {
document.getElementById('authenticateButton').disabled = true;
document.getElementById('authInfo').textContent = `Authentication successful! Code: ${code}`;
// Store the access token in local storage
localStorage.setItem('accessToken', code);
}
// Retrieve the access token from local storage
const accessToken = localStorage.getItem('accessToken');
// Check if the access token exists
if (accessToken) {
// Access token is available, you can use it in your code
console.log('Access Token:', accessToken);
document.getElementById('authInfo').textContent += `\nAccess Token: ${accessToken}`;
} else {
// Access token is not available or not set
console.log('Access Token not found');
document.getElementById('authInfo').textContent += '\nAccess Token not found';
}
</script>
</body>
</html>