Вопрос

Toying around with Soundclouds SDK for Python with an impact of TKinter as GUI. Now I want to generate a access token for each user so that I could access more API-endpoints.

I have created an applicaton in Soundclouds Developer portal with a link to my callback.

There is nothing corresponding to generating a access token for an desktop application. Only for server-side application. I tried this code below:

import soundcloud

# create client object with app credentials
client = soundcloud.Client(client_id='YOUR_CLIENT_ID',
                           client_secret='YOUR_CLIENT_SECRET',
                           redirect_uri='REDIRECT_URL')

# redirect user to authorize URL
redirect client.authorize_url()

I have set my keys, and redirect_uri as the callback on my webserver. When I run my python file from the terminal, I get this:

File "token.py", line 9
    redirect client.authorize_url()
                  ^
SyntaxError: invalid syntax

Using Python 2.7.5+

What is causing this? I want to generete my access token and print in later on.

Это было полезно?

Решение

The solution might be that I need to create an instance of an web browser window, make the user accept the app using Soundcloud connect. The I grab the url and sort out the "code" in the url. Exchanges the code against an access-token and stores it inside a text-file. So that I could grab it later on.

Другие советы

A simple way of obtaining an access token is by first authenticating via the User Credentials flow, which exchanges your username and password for an access token:

client = soundcloud.Client(client_id = 'CLIENT_ID',
                           client_secret = 'CLIENT_SECRET',
                           username = 'USERNAME',
                           password = 'PASSWORD')
print client.access_token

try:

redirect(client.authorize_url())
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top