这是我第一次尝试使用web。我正在尝试为显示名称https://github.com/Privo/PRIVO-Hub/wiki/Web-Services-API-Reference#update-user-display-name实现这个PRIVO。正如您所看到的,没有太多的解释或代码示例。
我要做的是使用HTTP接收一个有效的响应,这表明名称是正确的格式,然后我应该将这个显示名称保存在我们的google服务器上。我只需要上半场的帮助。稍后我将研究如何保存到云服务器上。
我面临的问题是,我不确定这是否是如何使用HTTP,我也不能100%确定我不应该使用POST或PUT。到目前为止,这就是我所拥有的,请让我知道我做错了什么。
AsyncHttpClient client = null;
String authorizationHeader = "token_type", "" + " " + "access_token", "");
client.addHeader("Authorization", authorizationHeader);
client.addHeader("Content-type", "application/json");
client.addHeader("Accept", "application/json");
String requestBody = "displayName=" + "hardcodedDisplayName";
String requestURL = "https://privohub.privo.com/api/" + "account/public/saveDisplayName?" + requestBody;
client.get(requestURL, new ResponseHandler(myClass.this, "displayName", new OnResponseHandler() {
@Override
public void onSuccess(int statusCode, String apiName, JSONObject response) {
if (statusCode == 200) {
Log.i(TAG, "Seems to be working")
}
}
@Override
public void onFailure(int statusCode, String apiName, String responseMessage) {
Log.i(TAG, "Fail: " + responseMessage);
}
@Override
public void onFailure(int statusCode, String apiName, JASONArray errorResponse) {
Log.i(TAG, "Fail: " + errorResponse);
}
@Override
public void onFailure(int statusCode, String apiName, JSONObject errorResponse) {
if (errorResponse != null) {
Log.i(TAG, "Fail: " + errorResponse);
}
}
})); 根据上述代码,我将得到以下响应
{“消息”:“未找到对象”、"validationErrors":[]、"responseTimestamp":1419278367177、"totalCount":-1、“状态”:“失败”、"resultCount":-1、“实体”:null}
这种反应意味着什么?它在onFailure(int statusCode,String apiName,JSONObject errorResponse)上失败,错误代码为404。
提前感谢!
发布于 2014-12-22 20:33:41
您应该使用API文档中说应该使用的任何方法。在这种情况下,既不是GET,也不是POST,而是PUT!
https://stackoverflow.com/questions/27609957
复制相似问题