我正在尝试获取 friend 的帖子,例如社交网络。因为,我无法在客户端使用 Easy 表使用“INNER JOIN”之类的东西,所以我必须使用自定义 api。这是我的方法:
Android 客户端:
List<Pair<String, String>> params = new ArrayList<Pair<String, String>>();
params.add(new Pair("id", user.getId()));
params.add(new Pair("otherParam", otherParam));
client.getClient().invokeApi("getFeed", "POST", params, new ApiJsonOperationCallback() {
@Override
public void onCompleted(JsonElement jsonElement, Exception exception, ServiceFilterResponse response) {
System.out.println("exception: " + exception.toString());
GsonBuilder gsonb = new GsonBuilder();
Gson gson = gsonb.create();
JsonArray array = jsonElement.getAsJsonArray();
for (int i = 0; i < array.size(); i++) {
postList.add(gson.fromJson(array.get(i).getAsJsonObject().toString(), Post.class));
}
}
});
feed.js:
var api = {
post: (request, response, next) => {
var query = {
sql: 'SELECT * FROM Posts INNER JOIN Friends ON Posts.userId = Friends.followingId WHERE Friends.followingId = @id ORDER BY Posts.createdAt DESC',
parameters: [
{ id: 'id', otherParam: 'otherParam' }
]
};
request.azureMobile.data.execute(query)
.then(function (results) {
response.json(results);
});
}
};
module.exports = api;
我什至不确定这是否是正确的方法,或者我们可以访问这样的简单表中的表,但异常打印中没有任何详细信息。异常(exception)是“处理请求时出错”。提前致谢。
最佳答案
您的代码非常接近 - 只是 SQL 语句的参数规范不太正确。您需要按以下格式指定参数:
var query = {
sql: 'SELECT * FROM Posts INNER JOIN Friends ON Posts.userId = Friends.followingId WHERE Friends.followingId = @id ORDER BY Posts.createdAt DESC',
parameters: [
{ name: 'id', value: 'id' },
{ name: 'otherParam', value: 'otherParam' }
]
};
此 API 引用位于 http://azure.github.io/azure-mobile-apps-node/module-azure-mobile-apps_src_data_execute.html .
要从服务器获取更多调试信息,您可以提高日志记录级别。如果您在本地运行,请使用附加命令行参数运行应用程序:
node --debug app.js ---logging.level silly
如果您在 Azure 上托管,则可以将应用程序日志记录(文件系统)的日志级别设置为详细并打开日志流。这将向您显示正在执行的确切 SQL 语句和参数。
关于java - Azure 移动应用程序自定义 api 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39057471/