2017-06-22 7 views
0

私はvolleyライブラリ(GET)を使用してコードを書いており、Djangoの残りのAPIからデータを取得する必要があります。AndroidのVolleyパラメータを持つURL

実際の問題は、私がログインしている間、私は、ユーザーIDを取得していますが、私はちょうど共有好みによってそのIDを保存したと私は財布の詳細を取得するには、URLにIDを渡す必要がありますが、私はエラー

BasicNetworkを取得しています.performRequest:予期しない応答コード403

public class Wallet extends AppCompatActivity { 

TextView all_tv1; 
Button credit_bt, debit_bt; 
SharedPreferences pref; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    overridePendingTransition(R.anim.fadein, R.anim.fadeout); 
    setContentView(R.layout.activity_wallet); 
    pref=getApplication().getSharedPreferences("Options", MODE_PRIVATE); 
    Integer Key_UserID=pref.getInt("UserId_Value", 0); 
    // String a = Key_UserID.toString(); 

/JSONリクエスト/ 文字列URI = "http://staging.exol.in/wallet/wallet/api/wallet-detail/+Key_UserID"。 RequestQueue requestQueue = Volley.newRequestQueue(this);

JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, uri, null, 
      new Response.Listener<JSONArray>() { 

       @Override 
       public void onResponse(JSONArray response) { 
        Toast.makeText(getApplicationContext(),"stop",LENGTH_SHORT).show(); 
        // String data = ""; 
        try { 
         for(int i=0; i< response.length(); i++) { 
          JSONObject obj = response.getJSONObject(i); 
          String tnx_id = obj.getString("tnx_id"); 
          String transition_type = obj.getString("transition_type"); 
          // String email = obj.getString("email"); 
          // System.out.print("\nggtrgtg"+user+"\ngfg"+amount); 

          Toast.makeText(getApplicationContext(),tnx_id + transition_type ,LENGTH_SHORT).show(); 
          // data = "" + id + "" + name + "" + email + ""; 
          //txtDisplay.setText(txtDisplay.getText()+"\n" + id + "" + name + "\n" + email + ""); 
          // Adds the data string to the TextView "results" 
         } 
        } 



        // Try and catch are included to handle any errors due to JSON 
        catch (JSONException e) { 
         // If an error occurs, this prints the error to the log 
         e.printStackTrace(); 
        } 


       } 
      }, 
      new Response.ErrorListener() { 
       @Override 
       public void onErrorResponse(VolleyError error) { 
        VolleyLog.d(TAG, "Error: " + error.getMessage()); 
        Toast.makeText(getApplicationContext(),"Faled Misreably" ,LENGTH_SHORT).show(); 
       } 
      }); 
    //add request to queue 
    requestQueue.add(jsonArrayRequest); 






    setTitle("Wallet Window"); 
    Toolbar toolbar1 = (Toolbar)findViewById(R.id.tool_bar); 
    setSupportActionBar(toolbar1); 











    all_tv1 = (TextView)findViewById(R.id.all_tv); 
    all_tv1.setMovementMethod(new ScrollingMovementMethod()); 



    credit_bt = (Button)findViewById(R.id.credit_details1__bt); 
    debit_bt = (Button) findViewById(R.id.debit_details1__bt); 


    credit_bt.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      Toast.makeText(getApplicationContext(), "Credit Tab", LENGTH_SHORT).show(); 
      Intent i = new Intent(getApplicationContext(), Wallet_Credit.class); 
      startActivity(i); 
      finish(); 
     } 
    }); 



    debit_bt.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      Toast.makeText(getApplicationContext(), "Debit Tab", LENGTH_SHORT).show(); 
      Intent i = new Intent(getApplicationContext(), Wallet_Debit.class); 
      startActivity(i); 
      finish(); 
     } 
    }); 



} 

}

+0

使用してください郵便法 –

+0

あるべきはず"http://staging.exol.in/wallet/wallet/api/wallet-detail/ "+Key_UserID – jagapathi

+0

あなたのURLを確認してくださいあなたはあなたのURLに適切にユーザIDの値を設定していません –

答えて

0

あなたのURI文字列が正しく設定されていない(「決算に注目してください)。その代わり

String uri = "http://staging.exol.in/wallet/wallet/api/wallet-detail/+Key_UserID"; 

のそれは

String uri = "http://staging.exol.in/wallet/wallet/api/wallet-detail/"+Key_UserID; 
+0

それはまだ動作していません –

+0

私はこれも "http://staging.exol.in/wallet/wallet/api/wallet-detail/32"を試しました –

+0

32人のユーザーIDです。このURLは郵便配達員で働いています –

関連する問題