0

次のような app.net URL がある場合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

photos.app.net は単なるリダイレクタです。これは 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 が表示されます。

于 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 に答える