我尝试连接到strava时遇到问题。我不知道在授权回调域中放什么。我放了localhost或127.0.0.1

当我运行应用程序时,出现以下错误
android - Strava“授权回调域存在的问题”-LMLPHP

这是代码:

public class MainActivity extends AppCompatActivity {

    static {
        AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
    }

    private static final int RQ_LOGIN = 1001;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        StravaLoginButton loginButton = (StravaLoginButton) findViewById(R.id.login_button);
        loginButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                login();
            }
        });
    }

    private void login() {
        Intent intent = StravaLogin.withContext(this)
                                    .withClientID(29519)
                                    .withRedirectURI("gekon.technologypark.cz")
                                    .withApprovalPrompt(AUTO)
                                    .withAccessScope(AccessScope.VIEW_PRIVATE_WRITE)
                                    .makeIntent();
        startActivityForResult(intent, RQ_LOGIN);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if(requestCode == RQ_LOGIN && resultCode == RESULT_OK && data != null) {
            Log.d("Strava code", data.getStringExtra(RESULT_CODE));
            AuthenticationConfig config = AuthenticationConfig.create()
                    .debug()
                    .build();
            AuthenticationAPI api = new AuthenticationAPI(config);
            LoginResult result = api.getTokenForApp(AppCredentials.with(29519, "8d55af50a97a9f4b5269670de00bf5e6f4b9942d "))
                    .withCode(RESULT_CODE)
                    .execute();
        }
    }


}


我已经看到redirectUri必须与回调域相同,所以我将localhost或127.0.0.1放进去,但是我仍然遇到此错误

最佳答案

您必须在http://参数中包含redirect_uri;例如如果将localhost设置为回调域:

https://www.strava.com/oauth/authorize?
    client_id=XXXXX&
    redirect_uri=http://localhost&
    response_type=code&
    scope=read_all,profile:read_all,activity:read_all

07-27 20:38