首页 > 解决方案 > Strava Api 令牌 Android

问题描述

我已经用 Strava 授权了我的应用程序,我想从中获取我的令牌。问题是在这段代码中

 LoginResult result = api.getTokenForApp(AppCredentials.with(29519, "8d55af50a97a9f4b5269670de00bf5e6f4b9942d "))
                                .withCode(code)
                                .execute();

我认为它永远不会运行,因为我看不到打印的 test5。它直接进入线程外的意图。另外,我如何从我的线程和我的类之外的 LoginResult 获取结果并使用

这是代码:

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

        Log.d("Strava code", "TEST1");


        if(requestCode == RQ_LOGIN && resultCode == RESULT_OK && data != null) {


            Thread thread = new Thread(new Runnable() {

                @Override
                public void run() {
                    try  {
                        String code = data.getStringExtra(StravaLoginActivity.RESULT_CODE);
                        Log.d("Strava code", "TEST2");

                        AuthenticationConfig config = AuthenticationConfig.create()
                                .debug()
                                .build();
                        Log.d("Strava code", "TEST3");

                        AuthenticationAPI api = new AuthenticationAPI(config);
                        Log.d("Strava code", "TEST4");

                        LoginResult result = api.getTokenForApp(AppCredentials.with(29519, "8d55af50a97a9f4b5269670de00bf5e6f4b9942d "))
                                .withCode(code)
                                .execute();
                        Log.d("Strava code", "TEST5");

                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                }

            });

            thread.start();

            Intent testInt= new Intent(MainActivity.this,TestActivity.class);
            startActivity(testInt);

        }

标签: androidmultithreadingapistrava

解决方案


推荐阅读