2011-11-14 100 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

如果你成功,你能分享代码吗? –