Created
May 15, 2015 02:32
-
-
Save bagpack/cfb67fa31c8e5a863750 to your computer and use it in GitHub Desktop.
Twitter Kit For Android:Support media/upload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TwitterUploadClient { | |
private final String UPLOAD_ENDPOINT = "https://upload.twitter.com"; | |
MediaService service; | |
final RestAdapter adapter; | |
TwitterUploadClient(TwitterAuthConfig authConfig, Session session, SSLSocketFactory sslSocketFactory, ExecutorService executorService) { | |
if(session == null) { | |
throw new IllegalArgumentException("Session must not be null."); | |
} else { | |
Gson gson = (new GsonBuilder()).registerTypeAdapterFactory(new SafeListAdapter()).registerTypeAdapterFactory(new SafeMapAdapter()).create(); | |
this.adapter = (new RestAdapter.Builder()).setClient(new AuthenticatedClient(authConfig, session, sslSocketFactory)).setEndpoint(UPLOAD_ENDPOINT).setConverter(new GsonConverter(gson)).setExecutors(executorService, new MainThreadExecutor()).build(); | |
} | |
} | |
public TwitterUploadClient(Session session) { | |
this(TwitterCore.getInstance().getAuthConfig(), session, TwitterCore.getInstance().getSSLSocketFactory(), TwitterCore.getInstance().getFabric().getExecutorService()); | |
} | |
public MediaService getMediaService() { | |
if(this.service == null) { | |
this.service = this.adapter.create(MediaService.class); | |
} | |
return (MediaService)this.service; | |
} | |
public interface MediaService { | |
@Multipart | |
@POST("/1.1/media/upload.json") | |
void upload(@Part("media") TypedFile media, Callback<MediaEntity> cb); | |
@Multipart | |
@POST("/1.1/media/upload.json") | |
void upload(@Part("media_data") String mediaData, Callback<MediaEntity> cb); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MediaEntity { | |
@SerializedName("media_id") | |
public final long mediaId; | |
@SerializedName("media_id_string") | |
public final String mediaIdString; | |
@SerializedName("size") | |
public final int size; | |
@SerializedName("image") | |
public final MediaEntity.Image image; | |
public MediaEntity(long mediaId, String mediaIdString, int size, MediaEntity.Image image) { | |
this.mediaId = mediaId; | |
this.mediaIdString = mediaIdString; | |
this.size = size; | |
this.image = image; | |
} | |
public static class Image { | |
@SerializedName("w") | |
public final int w; | |
@SerializedName("h") | |
public final int h; | |
@SerializedName("image_type") | |
public final String imageType; | |
public Image(int w, int h, String imageType) { | |
this.w = w; | |
this.h = h; | |
this.imageType = imageType; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyTwitterApiClient extends TwitterApiClient { | |
public MyTwitterApiClient(Session session) { | |
super(session); | |
} | |
public MyStatusesService getMyStatusesService() { | |
return this.getService(MyStatusesService.class); | |
} | |
public interface MyStatusesService { | |
@FormUrlEncoded | |
@POST("/1.1/statuses/update.json") | |
void update(@Field("status") String status, @Field("in_reply_to_status_id") Long inReplyToStatusId,@Field("media_ids") String mediaIds, Callback<Tweet> cb); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment