【问题标题】:Oauth2 doesnt open an browser and a token in an android appOauth2 不会在 Android 应用程序中打开浏览器和令牌
【发布时间】:2022-06-13 02:36:56
【问题描述】:

尝试在使用 java 的 Android 应用程序中使用 Oauth 授权流程。无需打开浏览器进行授权。我不知道我应该在这里问还是在api的网站上问

在 manifest.xml 中授予互联网权限

MainActivity.java:


import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button RankConfirm = findViewById(R.id.UsernameConfirm);
        RankConfirm.setOnClickListener(v -> {
               final EditText username_box = findViewById(R.id.OsuUsername);
               final  String Username = username_box.getText().toString();
               final TextView RankView = findViewById(R.id.RankView);
               API_Response.UpdateRank(Username,RankView);
        });}

    }

API.java


import android.util.Log;
import android.widget.TextView;

import java.io.IOException;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class API {
    public static void UpdateRank(String Username, TextView RankView) {
        Thread NetworkThread = new Thread ("NetworkThread"){
            private volatile String Rank = "nic";
            public void run() {
                OkHttpClient client1 = new OkHttpClient();
                Request request1 = new Request.Builder()
                        .url("https://osu.ppy.sh/oauth/authorize/?client_id=14403&redirect_uri=https://google.com&response_type=code&scope=public")
                        .build();
                try {
                    Response response1 = client1.newCall(request1).execute();
                    String Code = response1.body().string();
                    Log.e("Debug", Code);

                } catch (IOException e) {
                    Log.e("Debug", "IO exception1");
                }```

【问题讨论】:

    标签: java android oauth-2.0


    【解决方案1】:

    意识到我做错了,我应该使用 WebView

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-07
      • 2017-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-12
      • 2016-03-04
      • 2013-05-30
      相关资源
      最近更新 更多