0

当我有一个 app.net 网址时https://photos.app.net/5269262/1- 如何检索帖子的图像缩略图?

在上面的 url 上运行 curl 会显示重定向

bash-3.2$ curl -i https://photos.app.net/5269262/1
HTTP/1.1 301 MOVED PERMANENTLY
Location: https://alpha.app.net/pfleidi/post/5269262/photo/1

接下来给出一个 html 页面,其中包含以下形式的图像

img src='https://files.app.net/1/60621/aWBTKTYxzYZTqnkESkwx475u_ShTwEOiezzBjM3-ZzVBjq_6rzno42oMw9LxS5VH0WQEgoxWegIDKJo0eRDAc-uwTcOTaGYobfqx19vMOOMiyh2M3IMe6sDNkcQWPZPeE0PjIve4Vy0YFCM8MsHWbYYA2DFNKMdyNUnwmB2KuECjHqe0-Y9_ODD1pnFSOsOjH' data-full-width='2048' data-full-height='1536' 

在更大的<div>标签块内。

app.net 中的文件 api 允许检索缩略图,但我不知何故无法获得这些端点和以上 url 之间的链接。

4

2 回答 2

2

The photos.app.net is just a simple redirecter. It is not part of the API proper. In order to get the thumbnail, you will need to fetch the file directly using the file fetch endpoint and the file id (http://developers.app.net/docs/resources/file/lookup/#retrieve-a-file) or fetch the post that the file is included in and examine the oembed annotation.

In this case, you are talking about post id 5269262 and the URL to fetch that post with the annotation is https://alpha-api.app.net/stream/0/posts/5269262?include_annotations=1 and if you examine the resulting json document you will see the thumbnail_url.

于 2013-05-06T18:19:55.640 回答
0

为了完整起见,我想在这里(用Java)为我发布最终解决方案——它建立在Jonathon Duerig 的良好且被接受的答案之上:

private static String getAppNetPreviewUrl(String url) {

    Pattern photosPattern = Pattern.compile(".*photos.app.net/([0-9]+)/.*");
    Matcher m = photosPattern.matcher(url);
    if (!m.matches()) {
        return null;
    }
    String id = m.group(1);

    String streamUrl = "https://alpha-api.app.net/stream/0/posts/" 
         + id + "?include_annotations=1";

    // Now that we have the posting url, we can get it and parse 
    // for the thumbnail
    BufferedReader br = null;
    HttpURLConnection urlConnection = null;
    try {
        urlConnection = (HttpURLConnection) new URL(streamUrl).openConnection();
        urlConnection.setDoInput(true);
        urlConnection.setDoOutput(false);
        urlConnection.setRequestProperty("Accept","application/json");
        urlConnection.connect();

        StringBuilder builder = new StringBuilder();
        br = new BufferedReader(
                new InputStreamReader(urlConnection.getInputStream()));
        String line;
        while ((line=br.readLine())!=null) {
            builder.append(line);
        }
        urlConnection.disconnect();

        // Parse the obtained json
        JSONObject post = new JSONObject(builder.toString());
        JSONObject data = post.getJSONObject("data");
        JSONArray annotations = data.getJSONArray("annotations");
        JSONObject annotationValue = annotations.getJSONObject(0);
        JSONObject value = annotationValue.getJSONObject("value");
        String finalUrl = value.getString("thumbnail_large_url");

        return finalUrl;
    } .......
于 2013-05-20T10:46:12.450 回答