我使用firebase的auth(token, new Firebase.AuthListener())函数进行身份验证和访问数据,我发现有时需要很长时间(超过5分钟)才能完成身份验证。但这种情况在几个月前并没有发生。
我从https://developer.nest.com/documentation/cloud/firebase-client-libraries下载的 Firebase 库,所以我的 Firebase 库版本是 1.1.1。有人遇到过这种情况吗?
我曾尝试使用authWithCustomToken (...) 来替换auth (...),但它不起作用。如何在嵌套中使用此功能进行身份验证?
而且我发现firebase在他们的协议中添加了SSL,是导致上述情况的原因吗?
我从https://www.firebase.com/blog/2012-07-27-firebase-now-supports-ssl.html下载了一个 firebase.js ,但我不知道如何使用这个文件来创建一个 * .crt 或 *.cer 文件,有人可以帮助我吗?
/******************************* 更新 ***************** ******************/
以下是示例代码如下:
access_token 我已经通过 http 请求从巢获得,
String Access_Token_URL = "https://api.home.nest.com/oauth2/access_token";
URL u = new URL(Access_Token_URL);
HttpURLConnection conn = (HttpURLConnection) u.openConnection();
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestMethod("POST");
String cmd = "code="+pincode+"&client_id=" + Client_ID + "&client_secret="+ Client_secret +"&grant_type=authorization_code";
DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
wr.writeBytes(cmd);
wr.flush();
wr.close(); // flush and close
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = reader.readLine()) != null){
//do something
}
reader.close();
JSONObject stock_data = new JSONObject(line);
access_token = stock_data.getString("access_token"); //access_token="c.W6o3HEpUe3a..........";
我在 auth() 函数中使用 access_token,
String DataBase_URL = "https://developer-api.nest.com";
Firebase myDataBase = new Firebase(DataBase_URL);
myDataBase.auth(access_token, new Firebase.AuthListener(){
@Override
public void onAuthError(FirebaseError arg0) {
// TODO Auto-generated method stub
Log.i(TAG, "AuthErro: " + arg0.getMessage());
//to do something...
}
@Override
public void onAuthRevoked(FirebaseError arg0) {
// TODO Auto-generated method stub
Log.i(TAG, "AuthRevoked: " + arg0.getMessage());
//to do something...
}
@Override
public void onAuthSuccess(Object arg0) {
// TODO Auto-generated method stub
Log.i(TAG, "AuthSuccess " + arg0.toString());
//to do something...
}
});
获得AuthSuccess消息的时间超过 5 分钟,行为是否正确?如果没有,我应该如何修改我的代码?