我已经制作了一个简单的google cloud端点API,用于为它设置puurpose和android客户端。 这是一个Entyty类:
@Entity
public class TransactionRecord implements Serializable {
@Id Long id;
int price;
String comment;
public TransactionRecord () { }
public long getId() { return id; }
public int getPrice() { return price; }
public String getComment() { return comment; }
public void setPrice(int price) { this.price = price; }
public void setId(long id) { this.id = id; }
public void setComment(String comment) { this.comment = comment; }
}
我遇到一些麻烦的端点方法之一:
@ApiMethod(name = "listTransactions")
public CollectionResponse<TransactionRecord> getTransactionsList(@Named("count") int count) {
List<TransactionRecord> records = ofy().load().type(TransactionRecord.class).limit(count).list();
return CollectionResponse.<TransactionRecord>builder().setItems(records).build();
}
Android客户端运行良好,但如果我调用此方法,则js客户端返回false 这是我的代码:
<script type="text/javascript">
var gapiReady = false;
function api_init() {
console.log('api_init');
gapiReady = true;
var host = window.location.host;
var protocol = host.search('localhost') == -1 ? 'https://' : 'http://';
var ROOT = protocol + host + '/_ah/api';
gapi.client.load('transaction', 'v1', function(){transaction_load(100);}, ROOT);
}
function transaction_load(limit) {
console.log('transaction_load ' + limit);
if (gapiReady) {
gapi.client.transaction.listTransactions(limit).execute(function(resp) {
console.log('listTransactions resp: ' + resp + ' code: ' + resp.code);
if (resp.items) {
for(var t in resp.items) {
display_card(t.getPrice(), t.getComment());
}
}
});
} else {
console.log('API is not ready!');
}
}
</script>
<script src="https://apis.google.com/js/client.js?onload=api_init"></script>
使用API Explorer调用此方法将返回下一步:
{
"items": [
{
"id": "5629499534213120",
"price": 55,
"comment": "ggggg",
"kind": "transaction#resourcesItem"
},
{
"id": "5639445604728832",
"price": 55,
"comment": "gggg",
"kind": "transaction#resourcesItem"
},
{
"id": "5649391675244544",
"price": 55,
"comment": "ggggg",
"kind": "transaction#resourcesItem"
},
{
"id": "5659313586569216",
"price": 55,
"comment": "yhuy",
"kind": "transaction#resourcesItem"
},
{
"id": "5722646637445120",
"price": 5522,
"comment": "yhuyhhhgffg",
"kind": "transaction#resourcesItem"
}
],
"kind": "transaction#resources",
"etag": "\"...\""
}
并且控制台中的输出是:
listTransactions resp: false code: undefined
所以在js中出了什么问题,更重要的问题是我如何能够找出其他方法的错误,因为我用来开发Android应用程序而且我是js的新手。