所以我一直在嘗試為我的應(yīng)用程序鍛煉身份驗(yàn)證系統(tǒng)。我有一個(gè) REST API 正在運(yùn)行,它經(jīng)過(guò)測(cè)試可以使用筆記本電腦上的 CURL 與 Oauth2 身份驗(yàn)證一起使用,這樣我就可以獲得 API 的令牌。我的result變量doInBackground確實(shí)從我的 API 獲得 JSON 響應(yīng),提供訪(fǎng)問(wèn)令牌信息、它的生命等。就像我在result調(diào)試時(shí)得到這個(gè)值一樣: {"access_token":"4Oq6o8oAGRf4oflu3hrbsy18qeIfG1","expires_in":36000,"token_type":"Bearer","scope":"read write","refresh_token":"iocSNJ2PTVbph2RnWmcf0Zv69PDKjw"}但是,onPostExecute由于某種原因,我沒(méi)有被調(diào)用。這是我的代碼。login.javapublic class Login extends AppCompatActivity { Button LoginButton, RegButton; EditText uUserName, uPassWord; WSAdapter.SendAPIRequests AuthHelper; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); //SetupHomeBtn = (ImageButton) findViewById(R.id.SetupHomeBtn); LoginButton = (Button) findViewById(R.id.LoginButton); RegButton = (Button) findViewById(R.id.LoginRegister); uUserName = (EditText) findViewById(R.id.LoginUserBox); uPassWord = (EditText) findViewById(R.id.LoginPassBox); //AuthHelper = new WSAdapter().new SendDeviceDetails(); // Moves user to the main page after validation LoginButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // gets the username and password from the EditText String strUserName = uUserName.getText().toString(); String strPassWord = uPassWord.getText().toString(); // API url duh String APIUrl = "http://192.168.0.18:8000/auth/token/"; // If the user is authenticated, then transfer to the MainActivity page if (APIAuthentication(strUserName, strPassWord, APIUrl)){ startActivity(new Intent(Login.this, Posts.class)); } } });
1 回答

慕村9548890
TA貢獻(xiàn)1884條經(jīng)驗(yàn) 獲得超4個(gè)贊
所以我實(shí)際上只是想通了這一點(diǎn)。事實(shí)證明我的代碼運(yùn)行良好,只是當(dāng)我調(diào)試時(shí),我沒(méi)有意識(shí)到“運(yùn)行新線(xiàn)程”旁邊有一個(gè)按鈕或類(lèi)似的東西。然后它把我送到了onPostExecute
. 對(duì)不起,我是菜鳥(niǎo)。希望這可以對(duì)未來(lái)出現(xiàn)這個(gè)簡(jiǎn)單錯(cuò)誤的人有所幫助。
添加回答
舉報(bào)
0/150
提交
取消