Created
January 10, 2016 17:51
-
-
Save sirvon/63ed25fb43b8d15369f0 to your computer and use it in GitHub Desktop.
upload video to twitter via android client
This file contains hidden or 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 TwitterVideoApiClient extends TwitterApiClient{ | |
private static final String TWITTER_UPLOAD_URL = "https://upload.twitter.com"; | |
private RestAdapter twitterVideoApiClientAdapter; | |
public TwitterVideoApiClient(TwitterSession session) { | |
super(session); | |
final Gson gson = new GsonBuilder() | |
.registerTypeAdapterFactory(new SafeListAdapter()) | |
.registerTypeAdapterFactory(new SafeMapAdapter()) | |
.create(); | |
SSLSocketFactory sslSocketFactory = TwitterCore.getInstance().getSSLSocketFactory(); | |
TwitterAuthConfig authConfig = TwitterCore.getInstance().getAuthConfig(); | |
ExecutorService executorService = TwitterCore.getInstance().getFabric() | |
.getExecutorService(); | |
twitterVideoApiClientAdapter = new RestAdapter.Builder() | |
.setClient(new AuthenticatedClient(authConfig, session, sslSocketFactory)) | |
.setEndpoint(TWITTER_UPLOAD_URL) | |
.setConverter(new GsonConverter(gson)) | |
.setExecutors(executorService, new MainThreadExecutor()) | |
.build(); | |
} | |
public TwitterUploadVideoInitService videoUploadInitService() { | |
return twitterVideoApiClientAdapter.create(TwitterUploadVideoInitService.class); | |
} | |
public TwitterUploadVideoAppendService videoUploadAppendService() { | |
return twitterVideoApiClientAdapter.create(TwitterUploadVideoAppendService.class); | |
} | |
public TwitterUploadVideoFinalizeService videoUploadFinalizeService() { | |
return twitterVideoApiClientAdapter.create(TwitterUploadVideoFinalizeService.class); | |
} | |
public interface TwitterUploadVideoInitService { | |
@FormUrlEncoded() | |
@POST("/1.1/media/upload.json") | |
void initialize(@Field("command") String command, | |
@Field("media_type") String mediaType, | |
@Field("total_bytes") String totalBytes, | |
Callback<Media> callback); | |
} | |
public interface TwitterUploadVideoAppendService { | |
@Multipart | |
@POST("/1.1/media/upload.json") | |
void append(@Part("command") String command, | |
@Part("media_id") String mediaId, | |
@Part("segment_index") int segmentIndex, | |
@Part("media") TypedFile media, | |
Callback <Twitter> callback); | |
} | |
public interface TwitterUploadVideoFinalizeService { | |
@FormUrlEncoded() | |
@POST("/1.1/media/upload.json") | |
void finalize(@Field("command") String command, | |
@Field("media_id") String mediaId, | |
Callback<Twitter> callback); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment