您好我正在尝试使用Twitter Twitter POST video Request
的REST API上传视频在本文档中,我无法理解如何从我的Android代码中创建此命令。:
twurl -H upload.twitter.com "/1.1/media/upload.json" -d "command=INIT&media_type=video/mp4&total_bytes=4430752"
此外,我可以使用twitter4j发布状态更新和图像,是否需要reAuthenticate才能使用HTTP API:
protected Void doInBackground(String... args) {
Date date = new Date();
String status = date.toString();
Log.d("Status", status);
try {
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setOAuthConsumerKey(consumerKey);
builder.setOAuthConsumerSecret(consumerSecret);
// Access Token
String access_token = mSharedPreferences.getString(PREF_KEY_OAUTH_TOKEN, "");
// Access Token Secret
String access_token_secret = mSharedPreferences.getString(PREF_KEY_OAUTH_SECRET, "");
AccessToken accessToken = new AccessToken(access_token, access_token_secret);
Twitter twitter = new TwitterFactory(builder.build()).getInstance(accessToken);
// Update status
StatusUpdate statusUpdate = new StatusUpdate("@UserName : " +status);
if(((MyApplication)getActivity().getApplication()).getLinkPath() != null) { //getting image resource file
String s = "file://" + ((MyApplication) getActivity().getApplication()).getLinkPath();
Uri uri = Uri.parse(s);
InputStream is = getActivity().getContentResolver().openInputStream(uri);
Log.d("Logger", "Sending media");
statusUpdate.setMedia(s, is);
Log.d(s, "Sent media");
}
twitter4j.Status response = twitter.updateStatus(statusUpdate);
Log.d("Status", response.getText());
} catch (TwitterException e) {
Log.d("Failed to post!", e.getMessage());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return null;
}
}
答案 0 :(得分:2)
更新03/16/2018,新PR和Maven Repo
我创建了一个pull请求,在twitter4j中添加此功能。您可以在这里查看实现: Adding Chuncked, video upload