0

我在清单文件中添加了这段代码:

<data android:scheme="https"
                    android:host="strava"/>

然后调用隐式意图在 strava 中进行授权,如下所示:

btnConnect.setOnClickListener {
            val intentUri = Uri.parse("https://www.strava.com/oauth/mobile/authorize")
                .buildUpon()
                .appendQueryParameter("client_id", "CLIENT_ID")
                .appendQueryParameter("response_type", "code")
                .appendQueryParameter("approval_prompt", "auto")
                .appendQueryParameter("scope", "activity:read_all")
                .build()

            val intent = Intent(Intent.ACTION_VIEW, intentUri)
            startActivity(intent)
        }

但是在浏览器中出现这样的错误:

{"message":"Bad Request", "errors":[{"resource":"Application", "field":"redirect_url", "code":"invalid"}]}
4

1 回答 1

0

看看官方文档,section Requesting Access > Mobile Applications > Android

您需要指定redirect_uri参数:

val intentUri = Uri.parse("https://www.strava.com/oauth/mobile/authorize")
        .buildUpon()
        .appendQueryParameter("client_id", "1234321")
        .appendQueryParameter("redirect_uri", "https://www.yourapp.com")
        .appendQueryParameter("response_type", "code")
        .appendQueryParameter("approval_prompt", "auto")
        .appendQueryParameter("scope", "activity:write,read")
        .build()

val intent = Intent(Intent.ACTION_VIEW, intentUri)
startActivity(intent)
于 2020-07-14T14:51:48.813 回答