Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Ambient
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Daniel Furaev
Ambient
Commits
e158a403
Commit
e158a403
authored
2 years ago
by
Daniel Furaev
Browse files
Options
Downloads
Patches
Plain Diff
token generation
parent
8b543895
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/services/spotify.dart
+38
-39
38 additions, 39 deletions
lib/services/spotify.dart
with
38 additions
and
39 deletions
lib/services/spotify.dart
+
38
−
39
View file @
e158a403
...
@@ -9,8 +9,7 @@ import 'package:spotify_sdk/spotify_sdk.dart';
...
@@ -9,8 +9,7 @@ import 'package:spotify_sdk/spotify_sdk.dart';
class
Spotify
{
class
Spotify
{
final
clientId
=
'60cf1944b15d4f9fb223ba32ce6336d1'
;
final
clientId
=
'60cf1944b15d4f9fb223ba32ce6336d1'
;
final
clientSecret
=
'd2a2fd28d1c14d14babd781b8d5b52f5'
;
final
clientSecret
=
'd2a2fd28d1c14d14babd781b8d5b52f5'
;
final
email
=
'ambient.spotify@gmail.com'
;
final
code
=
"AQCSV8ivXmfyNPrIkq-1xlmsaRmW-zgcrQDKHEQG-axgIFooNsk7tj24-StF_4y3B5ALd4d-efCQM6NkOcyCkQFV4MkuC7kAr8B64Gum8gt5yuutckAFndFDK__HhMQIOyO49OCs7sJIK2e8VHRT5h6dMdCyKUvWg7udxiQSYUHglS97leWWtfo9u_GWK1p3P5Mr_Mg7OYG0DkzY&state=34fFs29kd09"
;
final
password
=
"Start123
\$
"
;
final
scope
=
final
scope
=
'user-library-modify playlist-modify-private playlist-read-private user-follow-read user-read-current-playing user-library-read user-read-private user-top-read user-follow-modify user-read-recent-played'
;
'user-library-modify playlist-modify-private playlist-read-private user-follow-read user-read-current-playing user-library-read user-read-private user-top-read user-follow-modify user-read-recent-played'
;
...
@@ -18,42 +17,44 @@ class Spotify {
...
@@ -18,42 +17,44 @@ class Spotify {
var
authToken
=
var
authToken
=
'BQBIbqReZny6ctqIobozxD8dh6w7DBcWLLOYGT3NtngJntXWztPp27C4FZigb55UdjbLnyn_BRw3DlFlwPpgBwU8AeIxXOZvw3fw1liR5zpsyJkVq2ndzXBH0P49p9otYmG9w0RkQy1S_SxVeaZlHHJuImXfL3ckYw5u3Z9iMMtn3i2vnhBJjBjxDHb_WHMEeiRPf14xubjRocD7RvRrJrv0fNNDborP4mdcTS3wUkIOgh-_x--9Y_OKGMOjy9XfN4EcuTFmUVyYPLSYhDB6acRlrK1f'
;
'BQBIbqReZny6ctqIobozxD8dh6w7DBcWLLOYGT3NtngJntXWztPp27C4FZigb55UdjbLnyn_BRw3DlFlwPpgBwU8AeIxXOZvw3fw1liR5zpsyJkVq2ndzXBH0P49p9otYmG9w0RkQy1S_SxVeaZlHHJuImXfL3ckYw5u3Z9iMMtn3i2vnhBJjBjxDHb_WHMEeiRPf14xubjRocD7RvRrJrv0fNNDborP4mdcTS3wUkIOgh-_x--9Y_OKGMOjy9XfN4EcuTFmUVyYPLSYhDB6acRlrK1f'
;
generateAuthToken
()
async
{
Future
<
String
>
generateAuthToken
()
async
{
String
encoded
=
base64Url
.
encode
(
'
$clientId
:
$clientSecret
'
.
codeUnits
);
String
encoded
=
base64Url
.
encode
(
'
$clientId
:
$clientSecret
'
.
codeUnits
);
try
{
try
{
final
response
=
await
http
.
post
(
final
response
=
await
http
.
post
(
Uri
.
parse
(
'https://accounts.spotify.com/api/token'
),
Uri
.
parse
(
"https://accounts.spotify.com/api/token"
),
headers:
{
"Content_type"
:
"application/x-www-form-urlencoded"
},
body:
{
body:
{
"grant_type"
:
"authorization_code"
,
"grant_type"
:
"client_credentials"
,
'client_id'
:
"
$clientId
"
,
"client_id"
:
clientId
,
"client_secrete"
:
"
$clientSecret
"
,
"client_secret"
:
clientSecret
'scope'
:
"
$scope
"
,
});
},
headers:
{
'Authorization'
:
encoded
,
},
);
final
responseJson
=
json
.
decode
(
response
.
body
);
authToken
=
responseJson
[
'access_token'
];
if
(
response
.
statusCode
==
200
)
{
print
(
200
);
Map
<
String
,
dynamic
>
tokenResponse
=
json
.
decode
(
response
.
body
);
authToken
=
tokenResponse
[
"access_token"
];
print
(
authToken
);
print
(
authToken
);
}
else
if
(
response
.
statusCode
==
400
)
{
print
(
400
);
Map
<
String
,
dynamic
>
tokenResponse
=
json
.
decode
(
response
.
body
);
print
(
tokenResponse
[
"error_description"
]);
}
else
{
print
(
"anderer"
);}
}
catch
(
e
)
{
}
catch
(
e
)
{
// TODO: Handle Error
// TODO: Handle Error
}
}
return
authToken
;
}
}
search
(
text
)
async
{
search
(
text
)
async
{
var
token
=
generateAuthToken
();
try
{
try
{
final
response
=
await
http
.
get
(
final
response
=
await
http
.
get
(
Uri
.
parse
(
'https://api.spotify.com/v1/search?q=
$text
&type=track'
),
Uri
.
parse
(
'https://api.spotify.com/v1/search?q=
$text
&type=track'
),
headers:
{
headers:
{
'Authorization'
:
'Bearer
$authToken
'
},
// 'Authorization': 'Bearer $authToken',
'Authorization'
:
'Bearer BQBIbqReZny6ctqIobozxD8dh6w7DBcWLLOYGT3NtngJntXWztPp27C4FZigb55UdjbLnyn_BRw3DlFlwPpgBwU8AeIxXOZvw3fw1liR5zpsyJkVq2ndzXBH0P49p9otYmG9w0RkQy1S_SxVeaZlHHJuImXfL3ckYw5u3Z9iMMtn3i2vnhBJjBjxDHb_WHMEeiRPf14xubjRocD7RvRrJrv0fNNDborP4mdcTS3wUkIOgh-_x--9Y_OKGMOjy9XfN4EcuTFmUVyYPLSYhDB6acRlrK1f'
},
);
);
final
responseJson
=
json
.
decode
(
response
.
body
);
final
responseJson
=
json
.
decode
(
response
.
body
);
print
(
responseJson
);
final
items
=
responseJson
[
'tracks'
][
'items'
]
as
List
;
final
items
=
responseJson
[
'tracks'
][
'items'
]
as
List
;
List
songList
=
items
.
map
((
item
)
=
>
Song
.
fromJson
(
item
))
.
toList
();
List
songList
=
items
.
map
((
item
)
=
>
Song
.
fromJson
(
item
))
.
toList
();
...
@@ -68,11 +69,9 @@ class Spotify {
...
@@ -68,11 +69,9 @@ class Spotify {
try
{
try
{
final
response
=
await
http
.
get
(
final
response
=
await
http
.
get
(
Uri
.
parse
(
'https://api.spotify.com/v1/search?q=genre=
$genre
'
),
Uri
.
parse
(
'https://api.spotify.com/v1/search?q=genre=
$genre
'
),
headers:
{
headers:
{
'Authorization'
:
'Bearer
$authToken
'
},
// 'Authorization': 'Bearer $authToken',
'Authorization'
:
//headers: {HttpHeaders.authorizationHeader: authToken},
'Bearer BQBIbqReZny6ctqIobozxD8dh6w7DBcWLLOYGT3NtngJntXWztPp27C4FZigb55UdjbLnyn_BRw3DlFlwPpgBwU8AeIxXOZvw3fw1liR5zpsyJkVq2ndzXBH0P49p9otYmG9w0RkQy1S_SxVeaZlHHJuImXfL3ckYw5u3Z9iMMtn3i2vnhBJjBjxDHb_WHMEeiRPf14xubjRocD7RvRrJrv0fNNDborP4mdcTS3wUkIOgh-_x--9Y_OKGMOjy9XfN4EcuTFmUVyYPLSYhDB6acRlrK1f'
},
);
);
final
responseJson
=
json
.
decode
(
response
.
body
);
final
responseJson
=
json
.
decode
(
response
.
body
);
final
items
=
responseJson
[
'tracks'
][
'items'
]
as
List
;
final
items
=
responseJson
[
'tracks'
][
'items'
]
as
List
;
...
@@ -92,7 +91,7 @@ class Spotify {
...
@@ -92,7 +91,7 @@ class Spotify {
try
{
try
{
var
response
=
await
http
.
get
(
var
response
=
await
http
.
get
(
Uri
.
parse
(
"https://api.spotify.com/v1/me"
),
Uri
.
parse
(
"https://api.spotify.com/v1/me"
),
headers:
{
HttpHeaders
.
a
uthorization
H
ea
d
er
:
authToken
},
headers:
{
'A
uthorization
'
:
'B
ea
r
er
$
authToken
'
},
);
);
return
response
;
return
response
;
}
catch
(
e
)
{
}
catch
(
e
)
{
...
@@ -104,7 +103,7 @@ class Spotify {
...
@@ -104,7 +103,7 @@ class Spotify {
try
{
try
{
var
response
=
await
http
.
get
(
var
response
=
await
http
.
get
(
Uri
.
parse
(
"https://api.spotify.com/v1/me/albums"
),
Uri
.
parse
(
"https://api.spotify.com/v1/me/albums"
),
headers:
{
HttpHeaders
.
a
uthorization
H
ea
d
er
:
authToken
},
headers:
{
'A
uthorization
'
:
'B
ea
r
er
$
authToken
'
},
);
);
return
response
;
return
response
;
}
catch
(
e
)
{
}
catch
(
e
)
{
...
@@ -116,7 +115,7 @@ class Spotify {
...
@@ -116,7 +115,7 @@ class Spotify {
try
{
try
{
var
response
=
await
http
.
get
(
var
response
=
await
http
.
get
(
Uri
.
parse
(
"https://api.spotify.com/v1/me/tracks"
),
Uri
.
parse
(
"https://api.spotify.com/v1/me/tracks"
),
headers:
{
HttpHeaders
.
a
uthorization
H
ea
d
er
:
authToken
},
headers:
{
'A
uthorization
'
:
'B
ea
r
er
$
authToken
'
},
);
);
return
response
;
return
response
;
}
catch
(
e
)
{
}
catch
(
e
)
{
...
@@ -128,7 +127,7 @@ class Spotify {
...
@@ -128,7 +127,7 @@ class Spotify {
try
{
try
{
var
response
=
await
http
.
put
(
var
response
=
await
http
.
put
(
Uri
.
parse
(
"https://api.spotify.com/v1/me/tracks?ids=
$track
"
),
Uri
.
parse
(
"https://api.spotify.com/v1/me/tracks?ids=
$track
"
),
headers:
{
HttpHeaders
.
a
uthorization
H
ea
d
er
:
authToken
},
headers:
{
'A
uthorization
'
:
'B
ea
r
er
$
authToken
'
},
);
);
return
response
;
return
response
;
}
catch
(
e
)
{
}
catch
(
e
)
{
...
@@ -140,7 +139,7 @@ class Spotify {
...
@@ -140,7 +139,7 @@ class Spotify {
try
{
try
{
var
response
=
await
http
.
delete
(
var
response
=
await
http
.
delete
(
Uri
.
parse
(
"https://api.spotify.com/v1/me/tracks?ids=
$track
"
),
Uri
.
parse
(
"https://api.spotify.com/v1/me/tracks?ids=
$track
"
),
headers:
{
HttpHeaders
.
a
uthorization
H
ea
d
er
:
authToken
},
headers:
{
'A
uthorization
'
:
'B
ea
r
er
$
authToken
'
},
);
);
return
response
;
return
response
;
}
catch
(
e
)
{
}
catch
(
e
)
{
...
@@ -152,7 +151,7 @@ class Spotify {
...
@@ -152,7 +151,7 @@ class Spotify {
try
{
try
{
var
response
=
await
http
.
get
(
var
response
=
await
http
.
get
(
Uri
.
parse
(
"https://api.spotify.com/v1/tracks/
$id
"
),
Uri
.
parse
(
"https://api.spotify.com/v1/tracks/
$id
"
),
headers:
{
HttpHeaders
.
a
uthorization
H
ea
d
er
:
authToken
},
headers:
{
'A
uthorization
'
:
'B
ea
r
er
$
authToken
'
},
);
);
return
response
;
return
response
;
}
catch
(
e
)
{
}
catch
(
e
)
{
...
@@ -165,7 +164,7 @@ class Spotify {
...
@@ -165,7 +164,7 @@ class Spotify {
var
response
=
await
http
.
get
(
var
response
=
await
http
.
get
(
Uri
.
parse
(
Uri
.
parse
(
"https://api.spotify.com/v1/recommendations/available-genre-seeds"
),
"https://api.spotify.com/v1/recommendations/available-genre-seeds"
),
headers:
{
HttpHeaders
.
a
uthorization
H
ea
d
er
:
authToken
},
headers:
{
'A
uthorization
'
:
'B
ea
r
er
$
authToken
'
},
);
);
return
response
;
return
response
;
}
catch
(
e
)
{
}
catch
(
e
)
{
...
@@ -177,7 +176,7 @@ class Spotify {
...
@@ -177,7 +176,7 @@ class Spotify {
try
{
try
{
var
response
=
await
http
.
get
(
var
response
=
await
http
.
get
(
Uri
.
parse
(
"https://api.spotify.com/v1/albums/
$id
"
),
Uri
.
parse
(
"https://api.spotify.com/v1/albums/
$id
"
),
headers:
{
HttpHeaders
.
a
uthorization
H
ea
d
er
:
authToken
},
headers:
{
'A
uthorization
'
:
'B
ea
r
er
$
authToken
'
},
);
);
return
response
;
return
response
;
}
catch
(
e
)
{
}
catch
(
e
)
{
...
@@ -189,7 +188,7 @@ class Spotify {
...
@@ -189,7 +188,7 @@ class Spotify {
try
{
try
{
var
response
=
await
http
.
get
(
var
response
=
await
http
.
get
(
Uri
.
parse
(
"https://api.spotify.com/v1/albums/
$id
/tracks"
),
Uri
.
parse
(
"https://api.spotify.com/v1/albums/
$id
/tracks"
),
headers:
{
HttpHeaders
.
a
uthorization
H
ea
d
er
:
authToken
},
headers:
{
'A
uthorization
'
:
'B
ea
r
er
$
authToken
'
},
);
);
return
response
;
return
response
;
}
catch
(
e
)
{
}
catch
(
e
)
{
...
@@ -201,7 +200,7 @@ class Spotify {
...
@@ -201,7 +200,7 @@ class Spotify {
try
{
try
{
var
response
=
await
http
.
get
(
var
response
=
await
http
.
get
(
Uri
.
parse
(
"https://api.spotify.com/v1/artists/
$id
"
),
Uri
.
parse
(
"https://api.spotify.com/v1/artists/
$id
"
),
headers:
{
HttpHeaders
.
a
uthorization
H
ea
d
er
:
authToken
},
headers:
{
'A
uthorization
'
:
'B
ea
r
er
$
authToken
'
},
);
);
return
response
;
return
response
;
}
catch
(
e
)
{
}
catch
(
e
)
{
...
@@ -213,7 +212,7 @@ class Spotify {
...
@@ -213,7 +212,7 @@ class Spotify {
try
{
try
{
var
response
=
await
http
.
get
(
var
response
=
await
http
.
get
(
Uri
.
parse
(
"https://api.spotify.com/v1/artists/
$id
/top-tracks"
),
Uri
.
parse
(
"https://api.spotify.com/v1/artists/
$id
/top-tracks"
),
headers:
{
HttpHeaders
.
a
uthorization
H
ea
d
er
:
authToken
},
headers:
{
'A
uthorization
'
:
'B
ea
r
er
$
authToken
'
},
);
);
return
response
;
return
response
;
}
catch
(
e
)
{
}
catch
(
e
)
{
...
@@ -225,7 +224,7 @@ class Spotify {
...
@@ -225,7 +224,7 @@ class Spotify {
try
{
try
{
var
response
=
await
http
.
get
(
var
response
=
await
http
.
get
(
Uri
.
parse
(
"https://api.spotify.com/v1/artists/
$id
/albums"
),
Uri
.
parse
(
"https://api.spotify.com/v1/artists/
$id
/albums"
),
headers:
{
HttpHeaders
.
a
uthorization
H
ea
d
er
:
authToken
},
headers:
{
'A
uthorization
'
:
'B
ea
r
er
$
authToken
'
},
);
);
return
response
;
return
response
;
}
catch
(
e
)
{
}
catch
(
e
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment