-1
twitter api를 사용하여 이미지를 twitter에 게시 할 수 있습니까?android에서 twitter api를 사용하여 이미지를 업로드하는 중
가능하면 어떻게해야할까요?
감사
twitter api를 사용하여 이미지를 twitter에 게시 할 수 있습니까?android에서 twitter api를 사용하여 이미지를 업로드하는 중
가능하면 어떻게해야할까요?
감사
이 시도 : Android Demo. 도움이되기를 바랍니다.
if(isConnected()){
OAuthService authService = new ServiceBuilder()
.provider(TwitterApi.class)
.apiKey(Constants.CONSUMER_KEY)
.apiSecret(Constants.CONSUMER_SECRET)
.callback(Constants.OAUTH_CALLBACK_URL)
.build();
final OAuthRequest request = new OAuthRequest(Verb.POST, "https://upload.twitter.com/1/statuses/update_with_media.json");
verifier = uri.getQueryParameter(Constants.IEXTRA_OAUTH_VERIFIER);
try {
Token token = getToken();
if(token!=null){
authService.signRequest(token, request);
MultipartEntity entity = new MultipartEntity();
entity.addPart("status", new StringBody("Your Status!")); // THIS IS THE TWITTER MESSAGE
entity.addPart("media", new FileBody(new File(uriString))); // THIS IS THE PHOTO TO UPLOAD
ByteArrayOutputStream out = new ByteArrayOutputStream();
entity.writeTo(out);
request.addPayload(out.toByteArray());
request.addHeader(entity.getContentType().getName(), entity.getContentType().getValue());
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch(IOException e){
e.printStackTrace();
}
progressDialog = ProgressDialog.show(this,Constants.LABEL_BLANK, "Uploading Image",true);
Thread requestThread = new Thread() {
public void run() {
try {
response = new JSONObject (request.send().getBody());
uiHandler.sendEmptyMessage(0);
}catch (JSONException e) {
Log.e("TOUR_APP_TAG", "JSONException Thrown: " + e.getMessage());
errorHandler.sendEmptyMessage(0);
}
}
};
requestThread.start();
}
...
...
final Handler uiHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
if(progressDialog != null)progressDialog.dismiss();
if(response.has("id"))
//your code
}
};
final Handler errorHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
if(progressDialog != null)progressDialog.dismiss();
//your code
}
};
당신은 공유 그림의 Twitter4J 라이브러리를 필요로하고 그 [하나 here
에서 취할 수 있습니다 및 이미지에게의
**
* To upload a picture with some piece of text.
*
*
* @param file The file which we want to share with our tweet
* @param message Message to display with picture
* @param twitter Instance of authorized Twitter class
* @throws Exception exception if any
*/
public void uploadPic(File file, String message,Twitter twitter) throws Exception {
try{
StatusUpdate status = new StatusUpdate(message);
status.setMedia(file);
twitter.updateStatus(status);}
catch(TwitterException e){
Log.d("TAG", "Pic Upload error" + e.getErrorMessage());
throw e;
}
}
중복 가능성을 게시 할 다음과 같은 방법을 사용할 수 있습니다 후 최신이어야한다 안드로이드에서 트위터에 사진] (http://stackoverflow.com/questions/9724142/post-pictures-to-twitter-in-android) –