Skip to content

Commit b46f8f5

Browse files
committed
Add authorization flows
1 parent 1da1204 commit b46f8f5

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Client Credentials Flow
2+
> The Client Credentials flow is used in server-to-server authentication. Only endpoints that do not access user information can be accessed. The advantage here in comparison with requests to the Web API made without an access token, is that a higher rate limit is applied.
3+
4+
You can authenticate via [Client Credentials Flow](https://developer.spotify.com/documentation/general/guides/authorization-guide/#client-credentials-flow) using the `ClientCredentialsFlow` class. Since you don't need any user authorization, you just have to initialize the class to start using it, compared to user-based authentication flows.
5+
6+
#### Parameters
7+
8+
- client_id (`str`) - The Spotify application's Client ID
9+
- client_secret (`str`) - The Spotify application's Client secret
10+
- token (`Token`, *optional*) - A token you already got
11+
12+
#### Example usage
13+
14+
```python
15+
import asyncio
16+
from spotipy2 import Spotify
17+
from spotipy2.auth import ClientCredentialsFlow
18+
19+
20+
# Print an artist's popularity score
21+
async def print_populairty_score(artist_id):
22+
# Authenticate using ClientCredentialsFlow
23+
spo_client = Spotify(
24+
ClientCredentialsFlow(
25+
client_id="client_id",
26+
client_secret="client_secret"
27+
)
28+
)
29+
30+
# Use the Spotify client to get artist's info
31+
async with spo_client as s:
32+
artist = await s.get_artist(artist_id)
33+
print(f"{artist.name}'s popularity score is {artist.popularity}/100")
34+
35+
# Print Ed Sheeran's popularity score
36+
asyncio.run(print_populairty_score("6eUKZXaKkcviH0Ku9w2n3V"))
37+
```

mkdocs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ nav:
2626
- Authentication:
2727
- getting-started/authentication/index.md
2828
- getting-started/authentication/token.md
29+
- Authorization Flows:
30+
- getting-started/authentication/authorization-flows/client-credentials-flow.md
2931

3032
markdown_extensions:
3133
- pymdownx.highlight

0 commit comments

Comments
 (0)