[英]Android - How to realize REST GET function for REST API in skydrive
Does anyone know how to use Skydrive REST API in Android? 有谁知道如何在Android中使用Skydrive REST API?
(documented here http://msdn.microsoft.com/de-de/library/live/hh243648.aspx ) (此处记录http://msdn.microsoft.com/de-de/library/live/hh243648.aspx )
All Data that are needed for access are already stored! 访问所需的所有数据都已存储!
private String AccessToken;
private String AuthenticationToken;
private String RefreshToken;
private String ExpiresIn;
private String Scope;
Is it right to use 是否正确使用
HttpClient client = new DefaultHttpClient();
Does anyone have a full example? 有没有人有完整的例子?
Any ideas or suggestion would be helpful. 任何想法或建议都会有所帮助。 Thank you.
谢谢。
You can do something like this. 你可以做这样的事情。
InputStream result = null;
HttpClient httpClient = new DefaultHttpClient();
HttpGet get = new HttpGet("https://apis.live.net/v5.0/me/albums?access_token=" + AccessToken); // For example
HttpResponse response = httpClient.execute(get);
if (response != null && response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
BufferedHttpEntity bufferedHttpEntity = new BufferedHttpEntity(response.getEntity());
result = bufferedHttpEntity.getContent();
} else {
// insert error handling
}
Depending on what request you are making you may need to use HttpPut
, HttpPost
, HttpDelete
, etc. instead of HttpGet
. 根据您的要求,您可能需要使用
HttpPut
, HttpPost
, HttpDelete
等代替HttpGet
。
- GET - Returns the representation of a resource.
GET - 返回资源的表示形式。
- POST - Adds a new resource to a collection.
POST - 向集合添加新资源。
- PUT - Updated to the location that was specified as the target URL, or add a resource there, add a resource if one does not exist.
PUT - 更新到指定为目标URL的位置,或在其中添加资源,添加资源(如果不存在)。
- DELETE - Deletes a resource.
DELETE - 删除资源。
If the request requires a body, you can add it with setEntity()
which takes an HttpEntity object. 如果请求需要正文,则可以使用带有HttpEntity对象的
setEntity()
添加它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.