Flickr Rest api(照片上传)

发布于 2024-12-15 11:45:54 字数 3622 浏览 1 评论 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) {

            }

这是我的上传代码,但每次我都会收到此错误 ------>

11-14 12:20:33.515: 信息/System.out(444):
err code =“100”msg =“无效的API密钥(密钥格式无效)”

请帮助我。提前致谢。

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) {

            }

This is my upload code but every time I am getting this error ------>

11-14 12:20:33.515: INFO/System.out(444):
err code="100" msg="Invalid API Key (Key has invalid format)"

Please help me. Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吲‖鸣 2024-12-22 11:45:54

如果您查看 Flickr 上传 API

100:API 密钥无效:
传递的 API 密钥无效或已过期。

所以我猜你的 API 密钥不正确。要使用 Flickr API,您需要拥有应用程序密钥。

目前,只有事先获得许可,才允许将该 API 用于商业用途。用于商业用途的 API 密钥请求由工作人员审核。

这是如何获取 API 密钥


没有照片指定
缺少照片所需参数。

If you take a look at the Flickr upload API

100: Invalid API Key:
The API key passed was not valid or has expired.

So I guess your API key was incorrect. To use the Flickr API you need to have an application key.

Currently, commercial use of the API is allowed only with prior permission. Requests for API keys intended for commercial use are reviewed by staff.

Here is how to get an API key


No photo specified
The photo required argument was missing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文