Post image on Twitter using Fracbic Android

Sep 18 2015 1:42 AM
I have a button use select image from Sdcard and display to ImageView 
btn_select.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, RESULT_LOAD_IMAGE);

}

});
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && data != null) {
selectedImage = data.getData();
img_status.setImageURI(selectedImage);
}}
 
 
And I have a button post image
btn_post_image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TwitterSession session=Twitter.getSessionManager().getActiveSession();
File mFile=new File(selectedImage.getPath());
typedFile=new TypedFile("application/octet-stream", mFile);
Log.e("KTERR", typedFile+"");

status=edt_status.getText().toString();
MyTwitterApiClient apiClient=new MyTwitterApiClient(session);
UploadMediaService uploadMediaService=apiClient.getUploadMediaService();
uploadMediaService.upload(typedFile, status, new Callback<Media>() {
@Override
public void success(Result<Media> result) {
Toast.makeText(getActivity(),"Upload Completed", Toast.LENGTH_SHORT).show();
}

@Override
public void failure(TwitterException e) {
Toast.makeText(getActivity(),"Error",Toast.LENGTH_SHORT).show();

}
});
}
});
public class MyTwitterApiClient extends TwitterApiClient {

public MyTwitterApiClient(TwitterSession session) {
super(session);
}

public UploadMediaService getUploadMediaService() {

return getService(UploadMediaService.class);
}


}

interface UploadMediaService {

@Multipart
@POST("1.1/media/upload.json")
void upload(@Part("media") TypedFile file, @Part("additional_owners") String owners, Callback cb);

}
It no working!
Can you help me, Please!
Thanks you very much 

Answers (1)