2

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

当我运行应用程序时,出现以下错误 在此处输入图像描述

这是代码:

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 必须与回调域相同,所以我输入了localhost127.0.0.1但我仍然收到此错误

4

1 回答 1

3

您必须包含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
于 2018-10-22T13:06:40.943 回答