0

I'm using quickblox server, and developing an app in Java. By now I have a wierd issue that in my activity i perform the login with APP_ID, AUTH_KEY and AUTH_SECRET and when I go to other fragment (not activity) I success to upload data. The problem is when I switch to another fragment and I try to pull out the data , result.isSuccess() return false and says that Token is required. I've searched about this token and I found some information about that but havent seen a way yet how to get it.

This is the code Where I put data (and it works fine):

HashMap<String, Object> fields = new HashMap<String, Object>();

    String username = usernamefield.getText().toString();
    String moza = mozafield.getText().toString();
    String yaad = yaadfield.getText().toString();
    fields.put("username", username);
    fields.put("from",moza);
    fields.put("whereto", yaad);

    QBCustomObject qbCustomObject = new QBCustomObject();
    qbCustomObject.setClassName("FromTo");  // your Class name
    qbCustomObject.setFields(fields);
    QBCustomObjects.createObject(qbCustomObject, new QBCallbackImpl() {
        @Override
        public void onComplete(Result result) {
            if (result.isSuccess()) {
                QBCustomObjectResult qbCustomObjectResult = (QBCustomObjectResult) result;
                QBCustomObject qbCustomObject = qbCustomObjectResult.getCustomObject();
                String getid  = qbCustomObject.getCustomObjectId();
                //String getusername = qbCustomObject.get
                Bundle bndl = new Bundle();
                bndl.putString("id", getid);
                callback.savedDetails(bndl);

            } else {
                Log.e("Errors",result.getErrors().toString());
            }

        }


    }); 

and this is where I try to pull the data and I'm getting the Token issue:

 QBCustomObjectRequestBuilder requestBuilder = new QBCustomObjectRequestBuilder();
        QBCustomObjects.getObjects("FromTo", requestBuilder, new QBCallbackImpl() {             
                     @Override
                    public void onComplete(Result result) {
                        super.onComplete(result);
                         if (result.isSuccess()) {
                             QBCustomObjectLimitedResult coresult = (QBCustomObjectLimitedResult) result;
                             ArrayList<QBCustomObject> co = coresult.getCustomObjects();
                             Log.d("Records: ", co.toString());
                         } else {
                             Log.e("Errors",result.getErrors().toString());
                         }
                    }
                 });
            }

The login code:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
               .
               .
               .
               .
 QBSettings.getInstance().fastConfigInit(String.valueOf(APP_ID), AUTH_KEY, AUTH_SECRET);
 QBUser user = new QBUser(myusername, mypassword);
 QBAuth.createSession(user , this , QBQueries.SIGN_IN);
                   .
                   .
@Override
    public void onComplete(Result result, Object context) { 
        QBQueries qbQueryType = (QBQueries) context;
        if (result.isSuccess()) {
            switch (qbQueryType) {
            case SIGN_IN:
             // return result from QBAuth.authorizeApp() query
             QBSessionResult qbSessionResult = (QBSessionResult) result;
             DataHolder.getDataHolder().setSignInUserId(qbSessionResult.getSession().getUserId());
             break;
            }
     }
   }

EDIT: I got the token, the qustion is where I have to use it?

Juvi
  • 1,078
  • 1
  • 19
  • 38

1 Answers1

0

Give this a shot:

try {
    BaseService.createFromExistentToken("31ed199120fb998dc472aea785a1825809ad5c04", date);
} catch (BaseServiceException e) {
    e.printStackTrace();
}
Mtl Dev
  • 1,604
  • 20
  • 29