需要Quickblox令牌

时间:2013-12-31 12:46:11

标签: quickblox

我正在使用quickblox服务器,并使用Java开发应用程序。 到目前为止,我有一个奇怪的问题,在我的活动中,我使用APP_ID,AUTH_KEY和AUTH_SECRET执行登录,当我转到其他片段(不是活动)时,我成功上传数据。 问题是当我切换到另一个片段并尝试提取数据时,result.isSuccess()返回false并表示需要令牌。 我搜索过这个令牌,我找到了一些关于这个的信息,但还没有看到如何获得它。

这是我放数据的代码(它工作正常):

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());
            }

        }


    }); 

这是我尝试提取数据的地方,我收到令牌问题:

 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());
                         }
                    }
                 });
            }

登录代码:

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;
            }
     }
   }

编辑:我收到了令牌,qustion是我必须使用的地方吗?

1 个答案:

答案 0 :(得分:0)

试一试:

try {
    BaseService.createFromExistentToken("31ed199120fb998dc472aea785a1825809ad5c04", date);
} catch (BaseServiceException e) {
    e.printStackTrace();
}