开发者

Invalid Signature when Uploading photo to flickr with Java

With the Flickr API - http://www.flickr.com/开发者_运维问答services/api/ When I try to upload a photo, it gives me Error 96: Invalid Signature.

This is my code:

    String sig = secret + "api_key" + key + "auth_token" + token;
    String signature = FlickrRequestFrob.MD5(sig);

    String request = "http://api.flickr.com/services/upload/";

    HttpClient client = new HttpClient();
    PostMethod postMethod = new PostMethod(request);
    //System.out.println("Api Sig" + signature);
    postMethod.addParameter("api_key",key);
    postMethod.addParameter("api_sig", signature);
    postMethod.addParameter("auth_token", token);
    postMethod.addParameter("is_public", "1");
    postMethod.addParameter("photo", "C:/DSC_0281.JPG");
    postMethod.addParameter("title", "Scary!");

    int status = client.executeMethod(postMethod);
    System.out.println("Status: " + status);

    InputStream responseStream = postMethod.getResponseBodyAsStream();

The response is:

Status: 200 Response:

<?xml version="1.0" encoding="utf-8" standalone="no"?><rsp stat="fail">
    <err code="96" msg="Invalid signature"/>
</rsp>

I have no clue why, someone can help me here?


The md5 signature needs to be done for your whole argument list, not only key and token.

So, in short: make a complete and SORTED argument-list (without '=' characters), and do the md5 hash over this. this should work.

See http://www.flickr.com/services/api/auth.spec.html chapter (8) for details.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜