如何检索照片预览在app.net

问题描述 投票:0回答:2

当我有一个app.net URL像https://photos.app.net/5269262/1 - 我怎么可以检索后的图像缩略图?

运行在上述网址的卷曲显示重定向

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>tags的较大的块。

在app.net文件API允许retrieve thumbnails但我有点不明白这些端点和上面的URL之间的联系。

image preview
2个回答
2
投票

该photos.app.net只是一个简单的redirecter。这不是正确的API的一部分。为了得到缩略图,则需要直接使用文件读取端点和文件ID(http://developers.app.net/docs/resources/file/lookup/#retrieve-a-file)来获取文件或者读取该文件包括在后并检查透过oEmbed注解。

在这种情况下,你所谈论的帖子ID 5269262和URL与注释是https://alpha-api.app.net/stream/0/posts/5269262?include_annotations=1,如果你检查生成的JSON文档,你会看到thumbnail_url获取这一职务。


0
投票

为了完整起见,我想在这里(在Java中)发布最终的解决方案,我 - 它建立在乔纳森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;
    } .......
© www.soinside.com 2019 - 2024. All rights reserved.