我正在整合Slack Api: Sign in with Slack。我从Slack Api有几件事。使用Slack Api登录,Android
我需要的code参数。
在我的Activity班中,我为此使用WebView。要访问code参数,在shouldOverrideUrlLoading方法我用:
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith("http://localhost:8000/")) {
UrlQuerySanitizer urlQuerySanitizer = new UrlQuerySanitizer(url);
String CLIENT_CODE = urlQuerySanitizer.getValue("code");
Log.e(TAG, "shouldOverrideUrlLoading: "+ CLIENT_CODE);
loginPresenter.loginSuccess();
return true;
} else {
view.loadUrl(url);
return true;
}
}
我做类叫HttpConstant保持网址:
public class HttpsConstant {
public static final String AUTHORIZATION_SLACK_URL = "https://slack.com/oauth/authorize?scope=identity.basic,identity.email,identity.avatar&client_id=something";
public static final String TOKEN_URL = "https://slack.com/";
}
我做类叫StrngConstant保持这样:CLIENT_ID, CLIENT_SECRET, CLIENT_CODE。
public final class StringConstant {
public static final String CLIENT_ID = "something";
public static final String CLIENT_SECRET = "something" ;
public static final String CLIENT_CODE = "something but still does not
able to pass the code parameter here from my activity class";
}
我使用Retrofit为登录服务:
public interface LoginService {
@GET("api/oauth.access?client_id=" + StringConstant.CLIENT_ID +
"&client_secret=" + StringConstant.CLIENT_SECRET +
"&code="+ StringConstant.CLIENT_CODE)
Call getLoginToken();
}
我已经在shouldOverrideUrl方法使用SharedPreferences但无法使用尝试。
SharedPreferences preferences = getSharedPreferences("ClientCode", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("Code", CLIENT_CODE);
editor.commit();
如何在登录服务中通过code参数?我怎样才能使用这个SharedPreferences,所以我可以访问code参数?或者,有没有其他方法可以获得code参数并使用它?