leanCloud使用的时候心得

来源:互联网 发布:手机图文设计软件 编辑:程序博客网 时间:2024/05/16 10:38
第一步:https://leancloud.cn/docs/rest_api.html#获取对象
先查看该文档清楚请求的格式 比如header里都需要什么参数 严格按照

第二步:https://leancloud.cn/dashboard/apionline/index.html#!/classes/查询对象_get_3
清楚自己客户端绑定的url及返回的参数:
https://leancloud.cn:443/1.1/classes/devices/58cfa8311b69e6006b8876ad
第三步:创建对应的app一些对应的参数
第四步:创建对应的表:创建表的时候注意ACL权限(重点)可读模式
第五步:代码示例:读取时候切记有的是response.body().toString();可读取内容
有的是response.body().string();;可读取内容
private static finalStringURL="https://leancloud.cn:443/1.1/classes/devices/58d0e2f244d90400684d26e4";
private static finalStringAPP_ID="onXRojJheCxxxxxx-gzGzoHsz";
private static finalStringAPP_KEY="SUB7qOw1qQvxxxxxxx";
public static voidcheckRegiste(finalActivity mainActivity) {

if(okHttpClient==null) {
OkHttpClient.Builder builder =newOkHttpClient.Builder();
okHttpClient= builder.build();
}
Request.Builder resBuilder =newRequest.Builder();
resBuilder.addHeader("X-LC-Id",APP_ID);
resBuilder.addHeader("X-LC-Key",APP_KEY);
// resBuilder.addHeader("Content-Type", "application/json");
resBuilder.url(URL
// + "devices?where=" + URLEncoder.encode("{\"open\":\"" + true + "\"}")
);

okHttpClient.newCall(resBuilder.build()).enqueue(newCallback() {

@Override
public voidonResponse(Call call, final Response response)throwsIOException {
newHandler(Looper.getMainLooper()).post(newRunnable() {
@Override
public voidrun() {
try{
JSONObject data =newJSONObject(response.body().string());
if(data.optBoolean("to_death")) {
mainActivity.finish();
return;
}
}catch(Exception e) {
e.printStackTrace();
}
}
});
}

@Override
public voidonFailure(Call call,IOException e) {
e.printStackTrace();
}
});
}
0 0
原创粉丝点击