2011-11-14 143 views
0
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) { 

      } 

這是我上傳的代碼,但我得到這個錯誤------>Flickr的REST API(上傳照片)

12月11日至14日每天時間:20:33.515:信息/System.out(444):
err code =「100」msg =「API密鑰無效(密鑰格式無效)」

請幫幫我。提前致謝。

回答

3

如果你看一看的Flickr upload API

100:無效的API密鑰: 傳遞的API密鑰無效或已過期。

所以我猜你的API密鑰不正確。要使用Flickr API,您需要有一個應用程序密鑰。

目前,API的商業用途只有經過事先許可才允許。工作人員審查用於商業用途的API密鑰的請求。

這裏是how to get an API key


沒有照片指定 照片所需的參數缺失。

+0

我改正了我的代碼現在它有另一個被稱爲錯誤代碼2沒有指定的照片 – Rocker

+0

如何指定照片參數請給我一些例子... – Rocker

+0

如果你成功,你能分享代碼嗎? –