使用 Java 将照片上传到 flickr 时签名无效
使用 Flickr API - http://www.flickr.com/services/api/ 当我尝试上传照片时,出现错误 96:签名无效。
这是我的代码:
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();
响应是:
状态:200 回复:
<?xml version="1.0" encoding="utf-8" standalone="no"?><rsp stat="fail">
<err code="96" msg="Invalid signature"/>
</rsp>
我不知道为什么,有人可以帮助我吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
md5 签名需要对整个参数列表进行,而不仅仅是密钥和令牌。
因此,简而言之:创建一个完整且已排序的参数列表(不带“=”字符),并对其进行 md5 哈希。这应该有效。
请参阅 http://www.flickr.com/services/api/auth.spec。 html第(8)章了解详细信息。
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.