询问者
Live SDK, SkyDrive can't get preview image

问题
-
LiveOperationResult operationResult = await disk.Client.GetAsync(file.ID+"/shared_read_link"); dynamic results = operationResult.Result; string sharedLink = results.link; var ob = BaseMethod.GetMethod("https://apis.live.net/v5.0/skydrive/get_item_preview?url=" + sharedLink.UrlEncode());
public static async Task<object> GetMethod(string url) { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); request.Method = "GET"; request.ContentType = "application/x-www-form-urlencoded"; request.Accept = "*/*"; WebResponse response = null; string responseStr = null; try { response = await request.GetResponseAsync(); if (response != null) { StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8); responseStr = reader.ReadToEnd(); reader.Dispose(); } } catch (Exception) { throw; } finally { request = null; response = null; } return responseStr; }
It will throw an exception "The remote server returned an error: (415) Unsupported Media Type." atresponse = await request.GetResponseAsync();
The request url is "https://apis.live.net/v5.0/skydrive/get_item_preview?url=https%3A%2F%2Fskydrive.live.com%2Fredir.aspx%3Fcid%3D3cc46a01f286fe39%26resid%3D3CC46A01F286FE39!136%26parid%3D3CC46A01F286FE39!114%26authkey%3D!AKH7VXwhgQKpT9Y" which return a 404 page in browser.
全部回复
-
Tested the url you request in Google chrome browser, its response is one JSON:
{ "error": { "code": "resource_not_found", "message": "The requested resource 'https://skydrive.live.com/redir.aspx?cid\u003d3cc46a01f286fe39\u0026resid\u003d3CC46A01F286FE39!136\u0026parid\u003d3CC46A01F286FE39!114\u0026authkey\u003d!AKH7VXwhgQKpT9Y' is missing a picture of type 'normal'." } }
And also I tested the original link you posted, the resource has been deleted. Please ensure the source can be accessed and exist in SkyDrive. For how to get the preview, yes, you could get from this document: http://msdn.microsoft.com/en-us/library/live/hh826545.aspx#previewBob Bao [MSFT]
MSDN Community Support | Feedback to us
-
Thank you for your reply and Sorry for my mistake:
Here is a share link: https://skydrive.live.com/redir.aspx?cid=3cc46a01f286fe39&resid=3CC46A01F286FE39!136&parid=3CC46A01F286FE39!114&authkey=!AHfuLroSMte612M
and its UrlEncode is https%3A%2F%2Fskydrive.live.com%2Fredir.aspx%3Fcid%3D3cc46a01f286fe39%26resid%3D3CC46A01F286FE39!136%26parid%3D3CC46A01F286FE39!114%26authkey%3D!AHfuLroSMte612M
so the actually url is
https://apis.live.net/v5.0/skydrive/get_item_preview?type=normal&url=https%3A%2F%2Fskydrive.live.com%2Fredir.aspx%3Fcid%3D3cc46a01f286fe39%26resid%3D3CC46A01F286FE39!136%26parid%3D3CC46A01F286FE39!114%26authkey%3D!AHfuLroSMte612M
The share link is right, but the response is
{ "error": { "code": "resource_not_found", "message": "The requested resource 'https://skydrive.live.com/redir.aspx?cid\u003d3cc46a01f286fe39\u0026resid\u003d3CC46A01F286FE39!136\u0026parid\u003d3CC46A01F286FE39!114\u0026authkey\u003d!AHfuLroSMte612M' is missing a picture of type 'normal'." } }
And it causes an exception in my app:The remote server returned an error: (404) Not Found.
I comment some code
//request.ContentType = "application/x-www-form-urlencoded"; //request.Accept = "*/*";