简体   繁体   English

Fortnite Tracker API似乎无法正常运行,或者我做错了什么?

[英]Fortnite Tracker API seems not to be working or I am doing something wrong?

I have run into one problem. 我遇到了一个问题。 I want to get data from fortnite tracker API , I have my own API key from the site and I am quite sure that I am doing everything fine but the site returns me ErrorInputStream with this message: 我想从Fortnite Tracker API中获取数据,我从网站上拥有自己的API密钥,并且我可以肯定我做得很好,但是该网站向我返回了ErrorInputStream并显示了以下消息:

{"message":"Invalid authentication credentials"}

I am 100% sure that I am giving right credintials to the site. 100%确信我给该网站提供了正确的凭据。

private RadioGroup radioGroup;
private EditText editText;

private static String APIKEY = "some-api-key";
private static String REQUEST_URL = "https://api.fortnitetracker.com/v1/profile/%platform%/%epic-nickname%";
private static String LOG_TAG = "INFO";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    radioGroup = findViewById(R.id.radioGroup);
    editText = findViewById(R.id.editText);
}

public void searchStats(View view) {
    if(editText.getText().toString().isEmpty()) {
        Toast.makeText(getApplicationContext(), "Please enter a nickname !", Toast.LENGTH_LONG).show();
        editText.requestFocus();
        return;
    }
    if(radioGroup.getCheckedRadioButtonId() == -1) {
        Toast.makeText(getApplicationContext(), "Please select a platform !", Toast.LENGTH_LONG).show();
        radioGroup.requestFocus();
        return;
    }

    DownloadTask dt = new DownloadTask();
    dt.execute();
}

private String getSelectedPlatformName(RadioGroup group) {
    RadioButton button =  findViewById(group.getCheckedRadioButtonId());
    return button.getText().toString().toLowerCase();
}

public class DownloadTask extends AsyncTask<String,Void,String> {

    @Override
    protected String doInBackground(String... strings) {
        URL url = null;
        try {
            url = new URL(REQUEST_URL.replaceAll("%platform%", getSelectedPlatformName(radioGroup)).replaceAll("%epic-nickname%", editText.getText().toString()));
            HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
            con.setRequestProperty("TRN-Api-Key", "some-api-key");
            InputStream inputStream;
            int responseStatusCode = con.getResponseCode();
            if( responseStatusCode != HttpURLConnection.HTTP_OK ) {
                inputStream = con.getErrorStream();
            } else {
                inputStream = con.getInputStream();
            }
            String data = IOUtils.toString(inputStream, con.getContentEncoding());
            System.out.println(data);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "done";
    }
}

} }

You need to set an User-Agent before you set the TRN-Api-Key! 您需要先设置用户代理,然后再设置TRN-Api-Key!

con.setRequestProperty("User-Agent", "Mozilla/5.0"); con.setRequestProperty(“ User-Agent”,“ Mozilla / 5.0”);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JPanel setColor()重复无法正常工作,或者我做错了什么? - JPanel setColor() repeatation is not working properly or am I doing something wrong? Javac无法正常工作,或者我做错了什么? - Javac not working properly or am I doing something wrong? Tomcat maxthreads,我做错了什么吗? - Tomcat maxthreads, am I doing something wrong? 编译器中的错误或我做错了什么? - Bug in compiler or am I doing something wrong? 为什么“包含”项不起作用? 还是我做错了? - Why is the 'contains' not working? or I am doing it wrong? 我的try-catch代码块做错什么了吗? - Am I doing something wrong with my try-catch block? 这是 Jackson JsonParser 中的错误,还是我做错了什么? - Is this a bug in the Jackson JsonParser, or am I doing something wrong? 没有命名为EntityManager的持久性提供程序-我做错了什么? - No Persistence provider for EntityManager named - I am doing something wrong? 我试图使用angularjs将数据从servlet提取到jsp中。 但是,ng-click似乎不起作用。 我究竟做错了什么? - I am trying to fetch data from a servlet into a jsp using angularjs. However, the ng-click seems to be not working. What am I doing wrong? 简单的加密/解密似乎无法正常工作,请帮助我找到我做错的事情 - Simple encryptio/decryption doesn't seems to work, help me find what i am doing wrong
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM