Slack Api: Sign in with Slack
を統合しています。私はSlack Api
からいくつか持っています。Slack Api、Androidでログイン
- クライアントID:秘密の '何か'
- クライアント: '何か'
- の許可URL:https://slack.com/oauth/authorize
- トークンURL:https://slack.com/api/oauth.access
- スコープ:私は必要
を識別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;
}
}
私は、URLを保つためにHttpConstant
というクラスますCLIENT_ID, CLIENT_SECRET, CLIENT_CODE
:
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
呼ばれます。
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<LoginResponse> 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
パラメータにアクセスできますか?または、他にもパラメータを取得してこれを使用する方法はありますか?
このLoginServiceクラスの内部。 getSharedPreferencesを解決することはできません。 –
インターフェイスは詳細な実装ではない宣言用です。そのパスでアクティビティまたはフラグメントまたは静的関数を使用するContex –
そのため、StringConstantクラスを使用しました。 –