Flickr rest api (Загрузка фотографий) - PullRequest
0 голосов
/ 14 ноября 2011
HttpClient httpclient = new DefaultHttpClient();
            HttpPost post = new HttpPost(
                    "http://api.flickr.com/services/upload/");
            HttpResponse response;
            try {
                response = httpclient.execute(post);
                HttpEntity entity = response.getEntity();
                if (entity != null) {
                    InputStream inputstream = entity.getContent();
                    BufferedReader bufferedreader = new BufferedReader(
                            new InputStreamReader(inputstream));
                    StringBuilder stringbuilder = new StringBuilder();
                    String currentline = null;
                    try {
                        while ((currentline = bufferedreader.readLine()) != null) {
                            stringbuilder.append(currentline + "\n");
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    String result = stringbuilder.toString();
                    System.out.println(result);
                }

                // HttpPost hp = new HttpPost(fma.upload_url);
                try {
                    Bitmap bm = BitmapFactory.decodeFile(file.toString()
                            + "/09102011079.jpg");
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    bm.compress(Bitmap.CompressFormat.JPEG, 50, baos);
                    byte[] b = baos.toByteArray();
                    ByteArrayBody bab = new ByteArrayBody(b, "");
                    MultipartEntity me = new MultipartEntity();
                    me.addPart("media", bab);
                    post.setEntity(me);
                    /*String s = "<root>" + "<entities>" + "<media>"
                            + "<size>" + "<large>" + "<width>700</width>"
                            + "<height>500<height>"
                            + "<resize>\"fit\"</resize>" + "</large>"
                            + "</size>" + "</media>" + "</entities>"
                            + "</root>";*/
                    /*
                     * try { se = new StringEntity(s); } catch
                     * (UnsupportedEncodingException e1) { // TODO //
                     * Auto-generated // catch // block //
                     * e1.printStackTrace(); // } // }
                     */
                    // ByteArrayEntity bae = new ByteArrayEntity(b); //
                    // hp.setEntity(se); // hp.setEntity(bae);
                    fma.consumer.sign(post);
                    DefaultHttpClient client = new DefaultHttpClient();
                    client.execute(post);
                } catch (OAuthMessageSignerException e) { 
                    System.out.println(e.getMessage());
                } catch (OAuthExpectationFailedException e) { 
                    System.out.println(e.getMessage());
                } catch (OAuthCommunicationException e) { 
                    System.out.println(e.getMessage());
                } catch (ClientProtocolException e) { 
                    System.out.println(e.getMessage());
                } catch (IOException e) { 
                    System.out.println(e.getMessage());
                }

            } catch (Exception e) {

            }

Это мой код загрузки, но каждый раз, когда я получаю эту ошибку ------>

11-14 12: 20: 33,515: INFO / System.out (444):
err code = "100" msg = "Неверный ключ API (ключ имеет неверный формат)"

Пожалуйста, помогите мне. Заранее спасибо.

1 Ответ

3 голосов
/ 14 ноября 2011

Если вы посмотрите на API загрузки Flickr

100: недействительный ключ API: Переданный ключ API недействителен или устарел.

Так что я думаю, ваш ключ API был неверным. Чтобы использовать Flickr API, вам нужен ключ приложения.

В настоящее время коммерческое использование API разрешено только с предварительного разрешения. Запросы на API-ключи, предназначенные для коммерческого использования, рассматриваются сотрудниками.

Вот как получить ключ API


Фото не указано Требуемый аргумент фото отсутствует.

...