Imgur API를 사용하여 이미지 업로드 모듈을 만들려고합니다 등록 후 클라이언트 ID와 클라이언트 비밀이 있습니다. 이 구현 및 테스트에 올 때, 그것은 실패하고 로그 캣업로드 후 이미지 링크를 가져 오지 못함
{"data":{"error":"We're really sorry, but
anonymous uploading in your country has
been disabled. Please <a href=\"\/register\">register
for an account<\/a> and try uploading again.","request":"\/3\/upload.json","method":"POST"}
,"success":false,"status":400}
아래의 로그 캣 응답에서 다음과 같은 응답을 제공하는 것은
public String uploadToImgur(File uploadFile) {
DefaultHttpClient defaulthttpclient;
HttpPost httppost;
MultipartEntity multipartentity;
String path = uploadFile.getAbsolutePath().toString();
String s;
defaulthttpclient = new DefaultHttpClient();
String targetURL = "https://api.imgur.com/3/upload.json";
String apikey = "client_secret";
httppost = new HttpPost(targetURL);
httppost.setHeader("User-Agent", USER_AGENT);
httppost.addHeader("Authorization", "Client-ID {client)_id}");
multipartentity = new MultipartEntity();
s = path.substring(1 + path.lastIndexOf("."));
if (s.lastIndexOf("jpg") >= 0)
{
s = "jpeg";
}
try
{
multipartentity.addPart("image", new FileBody(new File(path), (new StringBuilder("image/")).append(s).toString()));
multipartentity.addPart("key", new StringBody(apikey));
httppost.setEntity(multipartentity);
String s1 = EntityUtils.toString(defaulthttpclient.execute(httppost).getEntity());
Log.d("outpur" , s1);
if (s1.lastIndexOf("<original>") >= 0 && s1.indexOf("</original>") >= 0)
{
return (new StringBuilder("[img]")).append(s1.substring(10 + s1.lastIndexOf("<original>"), s1.indexOf("</original>"))).append("[/img]").toString();
}
}
catch (Exception exception)
{
return "ERRor";
}
return "Error";
}
당신이 말해 주시겠습니까 내 코드입니다 업로드 모듈을 향상시키는 더 좋은 방법은 무엇입니까?
I 돈의 OAuth2를 섹션을 방문하십시오; t 이해 ... 그게 내가 API를 사용하기 위해 어떤 코드를 얻을 수있을 것입니다? –
imgur가 표준 oAuth 프로토콜을 어떻게 따르는 지 설명하는이 문서 https://api.imgur.com/oauth2를 확인하십시오. 적어도 문서 및 메시지를받는 중에 익명으로 업로드하지 않으려면 액세스 토큰을 얻어야합니다. – Raghu