使用YODLEE API获取Y007错误“缺少授权标头”

时间:2017-04-18 02:39:29

标签: android yodlee

package com.example.shubhamshukla.icici;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.util.Log;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import cz.msebera.android.httpclient.Header;
import cz.msebera.android.httpclient.protocol.HTTP;
import io.card.payment.CardIOActivity;
import io.card.payment.CreditCard;

public class MainActivity extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener {

    Button scanCard,loginBtn;
    EditText username,password;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        scanCard = (Button)findViewById(R.id.scan);
        loginBtn =(Button)findViewById(R.id.login);
        username = (EditText)findViewById(R.id.username);
        password =(EditText) findViewById(R.id.password);
        final JSONObject[] JSONobj = {new JSONObject()};
        /////////////////////////////////////////////////////////////////////////////////////////////////////////
        RequestParams rp = new RequestParams();
        rp.put("Host","developer.api.yodlee.com");
        rp.put("Accept","application/json");
        rp.put("Content-Type", "application/json");
        rp.put("Content-Length","164");
        rp.put("Connection","keep-alive");
        rp.put("keep-alive","co-brand");
        rp.put("co-brand","cobrandLogin");
        rp.put("co-brand","cobrandPassword");
        rp.put("co-brand","locale");
        rp.put("cobrandLogin","sbCobshubham1109");
        rp.put("cobrandPassword","6595780d-7ea6-4e8a-a715-e14d2e198f8f");
        rp.put("locale","en_US");

        final MyHttpClient[] a = {new MyHttpClient()};
        a[0].post("/restserver/v1/cobrand/login",rp,new JsonHttpResponseHandler(){
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                try {
                    JSONObject serverResp = new JSONObject(response.toString());
                    JSONobj[0] = serverResp.getJSONObject("session");
                    Log.e("server resp", JSONobj[0]+"");
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }

        });
        loginBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RequestParams userRp = new RequestParams();
                userRp.put("Host","developer.api.yodlee.com");
                userRp.put("Accept","application/json");
                userRp.put("Content-Type", "application/json");
                userRp.put("Authorization",JSONobj[0]);
                userRp.put("Content-Length","138");
                userRp.put("Origin","https://developer.yodlee.com");
                userRp.put("Connection","keep-alive");
                userRp.put("keep-alive","user");
                userRp.put("user","loginName");
                userRp.put("loginName","sbMemshubham11091");
                userRp.put("user","password");
                userRp.put("password","sbMemshubham11091#123");
                userRp.put("user","locale");
                userRp.put("locale","en_US");
/*

                String mn = "doMemberLogin(userLogin=" +userName+ ", userPassword = " + userPassword + ", coBrandSessionCredential =" + loginTokens.get("cobSession") + " )";
                System.out.println(fqcn + " :: " + mn);
                final String requestBody="coBrandSessionCredential="+ loginTokens.get("cobSession")+"&loginName=" + userName + "&password="+ userPassword;
                String userLoginURL = localURLVer1 + "user/login";
                //HTTP.addHeaders("Authorization" , loginTokens.get("cobSession"));
                String jsonResponse = HTTP.doPostUser(userLoginURL,loginTokens, requestBody,true);
                UserContext member = (UserContext) GSONParser.handleJson(jsonResponse, yodlee.ysl.api.beans.UserContext.class);
                // Change the toString() method of the class to decide what to display on the Console.
                System.out.println(member.toString());
                loginTokens.put("userSession", member.getUser().getSession().getUserSession());*/



                Log.e("hrader COntent",userRp.toString());

               // Toast.makeText(MainActivity.this,username.getText().toString()+password.getText().toString(),Toast.LENGTH_LONG).show();
                new MyHttpClient().post("/restserver/v1/user/login",userRp,new JsonHttpResponseHandler(){
                    @Override
                    public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                        try {
                            JSONObject serverResp = new JSONObject(response.toString());
                            String userSess = serverResp.getJSONObject("session").getString("userSession");
                            Toast.makeText(MainActivity.this,userSess,Toast.LENGTH_LONG).show();
                            Log.e("USer",userSess);
                        } catch (JSONException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
                        Log.e("USer ERR",statusCode+throwable.toString()+errorResponse.toString());
                        Toast.makeText(MainActivity.this,statusCode+throwable.toString()+errorResponse.toString()+"",Toast.LENGTH_LONG).show();
                    }
                });

            }
        });



    }
}

这是传递的标题格式..

 04-18 08:00:21.762 5184-5184/com.example.shubhamshukla.icici E/hrader COntent: Origin=https://developer.yodlee.com&password=sbMemshubham11091#123&keep-alive=user&Accept=application/json&loginName=sbMemshubham11091&Connection=keep-alive&Host=developer.api.yodlee.com&Content-Length=138&locale=en_US&user=locale&Content-Type=application/json&Authorization={"cobSession":"08062013_2:cfd8b1f204e1285f05778bfec6de14bce6d8b2e42eea1329099949c466680ab74759b41b2423727d5c5b6d255b5dcadfa5e801294083b6d44d5f9e2233f74999"}

错误代码在这里..

未经授权 “errorCode”:“Y007”,“errorMessage”:“缺少授权标头”,“referenceCode”:“K1492482625709j4Z27t”

2 个答案:

答案 0 :(得分:0)

不确定,但似乎需要设置HTTP连接属性以设置授权。

conn.setRequestProperty(“授权”,cobSession);

答案 1 :(得分:0)

您可以使用Yodlee Developer Portal快速登录,使用以下链接检查Cobrand和用户令牌的身份验证,然后根据此页面上的指示进行尝试。

https://developer.yodlee.com/apidocs/index.php