简体   繁体   English

Volley:未发现身份验证挑战

[英]Volley: No authentication challenges found

I'm using Volley in an Android App to fetch data from the Misfit API ( http://build.misfit.com ). 我在Android应用程序中使用Volley从Misfit API( http://build.misfit.com )获取数据。 I tried to construct an intermittent activity, after someone logged in, to get all the data from the API. 在有人登录后,我试图构造一个间歇性活动,以从API获取所有数据。 In that activity, I perform a JsonObject GET request, that should give me some information about the user of the app. 在该活动中,我执行一个JsonObject GET请求,该请求应为我提供有关该应用程序用户的一些信息。 Here's the code so far: 到目前为止的代码如下:

package com.iss_fitness.myapplication;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.Volley;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import learn2crack.weboauth2.R;

public class LoadingScreenActivity extends Activity {

    //Introduce an delay
    private final int WAIT_TIME = 500;
    private static final String QUERY_URL = "https://api.misfitwearables.com/move/resource/v1/user/me/profile";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        System.out.println("LoadingScreenActivity  screen started");
        setContentView(R.layout.loading_screen);
        findViewById(R.id.mainSpinner1).setVisibility(View.VISIBLE);

        // Instantiate the RequestQueue.
        final RequestQueue queue = Volley.newRequestQueue(this);

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                executeJson();
                System.out.println("Going to Profile Data");
                /* Create an Intent that will start the ProfileData-Activity. */
                Intent mainIntent = new Intent(LoadingScreenActivity.this, DataView.class);
                LoadingScreenActivity.this.startActivity(mainIntent);
                LoadingScreenActivity.this.finish();
            }
        }, WAIT_TIME);
    }

    private Response.ErrorListener createRequestErrorListener() {

        return new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                System.out.println(error);
            }
        };
    }

    private void executeJson() {
        SharedPreferences prefs = this.getSharedPreferences("AppPref", MODE_PRIVATE);
        final String token = prefs.getString("token", null);
        RequestQueue queue = Volley.newRequestQueue(this);
        Map<String, String> params = new HashMap<String, String>();
        System.out.println(token);
        params.put("access_token", token);
        CustomRequest jsonRequest = new CustomRequest(Request.Method.GET, QUERY_URL, params,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        System.out.println(response);
                    }
                }, this.createRequestErrorListener());
        System.out.println(jsonRequest);
        queue.add(jsonRequest);
    }
}

I'm quite new to Android development, so please bear with me, I'll try to describe the code. 我是Android开发的新手,请耐心等待,我将尽力描述代码。 I've implemented a help class as suggested for JsonObjectRequest, as, as I understood, you can't override the getparams method when defining a request locally. 我已经实现了JsonObjectRequest所建议的帮助类,因为据我了解,在本地定义请求时不能覆盖getparams方法。 the executeJson() method is the interesting one: I get the user access token from my SharedPreferences (Where it's correctly stored), put that in a String Map and give that to the CustomRequest, where, inside the help class, it gets thrown into a getparams method that simply returns the params. executeJson()方法是一个有趣的方法:我从SharedPreferences(正确存储它的位置)中获取用户访问令牌,将其放入String Map中,然后将其提供给CustomRequest,在该类中将其扔到帮助类中一个仅返回参数的getparams方法。 The responselistener sadly never gets called, as the errorlistener reports the following: 可悲的是,由于错误侦听器报告以下内容,因此永远不会调用responselistener:

com.android.volley.NoConnectionError: java.io.IOException: No authentication challenges found

According to the API reference of Misfit, that should work. 根据Misfit的API参考,应该可以使用。 Now, I know that a GET request requires "headers" and not "params" but does that make any difference? 现在,我知道GET请求需要“标头”而不是“ params”,但这有什么区别吗?

Okay, I found a solution. 好吧,我找到了解决方案。 The helper class contained an overriding getparams method, but no getheaders method. helper类包含一个重载的getparams方法,但没有getheaders方法。 GET request requires getheaders, post requires getparams. GET请求需要getheaders,post需要getparams。

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

相关问题 Android Volley - HTTP代码401- java.io.IOException的奇怪错误:未找到身份验证挑战 - Android Volley - Strange Error with HTTP code 401- java.io.IOException: No authentication challenges found 使用twitter4j“没有发现身份验证挑战” - “No authentication challenges found” with twitter4j twitter4j找不到身份验证挑战 - twitter4j no authentication challenges found java.io.IOException:未找到身份验证质询 - java.io.IOException : No authentication challenges found Android 4.3 HTTPUrlConnection + Basic Auth - 未发现身份验证质询 - Android 4.3 HTTPUrlConnection + Basic Auth - No authentication challenges found 来自具有浏览器用户身份验证的Android的Twitter4J错误:未找到身份验证问题 - Error with Twitter4J from Android with browser user authentication: No authentication challenges found 为什么我得到android java.io.IOException:找不到身份验证挑战? - Why do I get android java.io.IOException: No authentication challenges found? 使用 volley 验证失败 - Authentication failed using volley 身份验证错误:无法应对任何这些挑战:{} Android - 401未经授权 - Authentication error: Unable to respond to any of these challenges: {} Android - 401 Unauthorized 为什么在 Android 中无法在 volley 中找到 ImageLoader - Why ImageLoader cannot be found in volley in Android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM