Upload audio url in twitter android - android

i am stuck in Twitter integration.I am done with image uploading through url but i am not able to upload audio or video url to twitter.
Any help is appreciated. Thanx guys
Twitter Code for uploading youtube url:
twitter.updateStatus("This is My Youtube url Test http://youtu.be/pfHxl46KyZM");
Logcat:
403:The request is understood, but it has been refused. An accompanying error message will explain why. This code is used when requests are being denied due to update limits (https://support.twitter.com/articles/15364-about-twitter-limits-update-api-dm-and-following).
message - Error creating status.
code - 189
Relevant discussions can be found on the Internet at:
http://www.google.co.jp/search?q=b2b52c28 or
http://www.google.co.jp/search?q=12c480e1
TwitterException{exceptionCode=[b2b52c28-12c480e1], statusCode=403, message=Error creating status., code=189, retryAfter=-1, rateLimitStatus=null, version=3.0.6-SNAPSHOT}

String tweetUrl = "https://twitter.com/intent/tweet?text=Put your Audio URL here &url="
+ "https://www.google.com&hashtags=android,twitter";
Uri uri = Uri.parse(tweetUrl);
startActivity(new Intent(Intent.ACTION_VIEW, uri));
OR
// Consumer
Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
// Access Token
AccessToken accessToken = null;
accessToken = new AccessToken(ACCESS_TOKEN, ACCESS_SECRET);
twitter.setOAuthAccessToken(accessToken);
// Posting Status
Status status = null;
try {
status = twitter.updateStatus("YOUR_AUDIO_LINK");
} catch (TwitterException e) {
e.printStackTrace();
}
System.out.println("Successfully updated the URL: "
+ status.getText());

You cannot upload video directly to Twitter - they simply don't support it.
Follow these steps.
1.Upload the video to a 3rd party service (like YouTube)
2.Get the public URL of the uploaded video
3.Add the URL to the status you send to Twitter - e.g. "Look at my Birtday video http://youtube.com/id"
If you want, you can add a thumbnail of the video as an image attachment
Hope this is what you are looking for.
Note sure but check if this helps you:-
String videoPath="video file path";
TwitterSession twitterSession = new TwitterSession(MainActivity.this);
AccessToken accessToken = twitterSession.getAccessToken();
Values values = new Values();
values.setSession(new Session());
TwitvidApi api = new TwitvidApi(values);
api.setSecureUrlEnabled(false);
Session session;
try {
session = api.authenticate(new TwitterAuthPack.Builder()
.setConsumerKey(twitter_consumer_key)
.setConsumerSecret(twitter_secret_key)
.setOAuthToken(accessToken.getToken())
.setOAuthTokenSecret(accessToken.getTokenSecret()).build());
api.getValues().setSession(session);
final UploadHelper helper = new UploadHelper(api);
File file = new File(videoPath);
TwitvidPost twitvidPost = new TwitvidPost.Builder().setFile(file)
.setChunkSize(10485760).setMessage("Twitvid test")
.setPostToTwitter(true).create();
try {
if (helper.upload(twitvidPost)) {
Toast.makeText(MainActivity.this, "Posted on Twitter and Twitvid" ,Toast.LENGTH_LONG).show();
Log.d("MainActivity", "Posted on Twitter and Twitvid");
} else {
Toast.makeText(MainActivity.this, "Post failed", Toast.LENGTH_LONG)
.show();
Log.d("MainActivity", "Posted failed");
}
} catch (Exception e) {
e.printStackTrace();
}
} catch (ApiException e1) {
e1.printStackTrace();
}

Related

How to upload media to twitter from background of application without showing any UI to user except login screen once?

I have tried to visit twitter developer website
but i was not getting proper answer from there as i tried different ways to solve this problem but i did found TweetComposer.Builder still i was not able to work with it.
i have found solution for my question i have downloaded and integrated a library from here with the help of this library i am able to post multiple media
Step 1:
first login to twitter by integrating library from this link according to guidance
Step 2:
After that you will be able to login with twitter and you will get two things 1)authToken.token and 2)authToken.secret store this for further use.
Step 3:
public void updateTwitterStatus() {
new AsyncTask() {
#Override
protected void onPreExecute() {
super.onPreExecute();
}
#Override
protected Object doInBackground(Object[] params) {
try {
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setOAuthConsumerKey(getResources().getString("YOUR_TWITTER_CONSUMER_KEY"));
builder.setOAuthConsumerSecret(getResources().getString("YOUR_TWITTER_CONSUMER_SECRET"));
// Access Token
String access_token = sharedPreferences.getString("authToken.token", "");
// Access Token Secret
String access_token_secret = sharedPreferences.getString("authToken.secret", "");
twitter4j.auth.AccessToken accessToken = new twitter4j.auth.AccessToken(access_token, access_token_secret);
twitter4j.Twitter twitter = new TwitterFactory(builder.build()).getInstance(accessToken);
// Update status for single image upload with raw folder
StatusUpdate statusUpdate = new StatusUpdate("posted from my app");
InputStream is = getResources().openRawResource(R.raw.lakeside_view);
statusUpdate.setMedia("test.jpg", is);
// Update status for single image upload with file
/*String statusMessage = "posted from my app";
StatusUpdate statusUpdate = new StatusUpdate(statusMessage);
statusUpdate.setMedia(file);*/
// Update status for multiple images upload with file
/*String statusMessage = "Hey I am posting 2 images of xyz event";
File imagefile1 = new File(Environment.getExternalStorageDirectory()+"/images/image_1.jpg");
File imagefile2 = new File(Environment.getExternalStorageDirectory()+"/images/image_2.jpg");
long[] mediaIds = new long[2];
UploadedMedia media1 = twitter.uploadMedia(imagefile1);
mediaIds[0] = media1.getMediaId();
UploadedMedia media2 = twitter.uploadMedia(imagefile2);
mediaIds[1] = media2.getMediaId();
StatusUpdate statusUpdate = new StatusUpdate(statusMessage);
statusUpdate.setMediaIds(mediaIds);*/
// to post twit
twitter4j.Status response = twitter.updateStatus(statusUpdate);
Log.d("Status", response.getText());
} catch (twitter4j.TwitterException e) {
Log.d("Failed to post!", e.getMessage());
}
return null;
}
#Override
protected void onPostExecute(Object o) {
*//* Dismiss the progress dialog after sharing *//*
Toast.makeText(getApplicationContext(), "Posted to Twitter!", Toast.LENGTH_SHORT).show();
super.onPostExecute(o);
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
i have tried this code it works for me.

Get url from uploaded video on facebook

In my app you can share the video you have just taken. I want to get the link to the video back to android so i can call another function that will input the link in the database. So basically i need to know how to get a link from video i just shared. I am using the following code.
String path;
//get the current active facebook session
Session session = Session.getActiveSession();
//If the session is open
if(session.isOpened()) {
//Get the list of permissions associated with the session
List<String> permissions = session.getPermissions();
//if the session does not have video_upload permission
if(!permissions.contains("video_upload")) {
//Get the permission from user to upload the video to facebook
Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(Main_activity.this, Arrays.asList("video_upload"));
session.requestNewReadPermissions(newPermissionsRequest);
}
path = getImagePath(videoUri); //function that gets absolute path
//Create a new file for the video
File file = new File(path);
try {
//create a new request to upload video to the facebook
Request videoRequest = Request.newUploadVideoRequest(session, file, new Request.Callback() {
#Override
public void onCompleted(Response response) {
if(response.getError()==null)
{
Toast.makeText(Main_activity.this, "video shared successfully", Toast.LENGTH_SHORT).show();
Log.i("it","worked");
String atbilde =response.getGraphObject().getProperty("id").toString();
}
else
{
Toast.makeText(Uzdevumi.this, response.getError().getErrorMessage(), Toast.LENGTH_SHORT).show();
}
}
});
//Execute the request in a separate thread
videoRequest.executeAsync();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
//Session is not open
else {
Toast.makeText(getApplicationContext(), "Please login to facebook first", Toast.LENGTH_SHORT).show();
}
}
});
Edit: Changed the "String atbilde =" so it would store the video id, so now i just need to build the url by simply adding "https://www.facebook.com/video.php?v=" before the id.
The response you receive if the upload of the Video was successful should contain an id property, see
https://developers.facebook.com/docs/graph-api/reference/v2.1/user/videos/#publish
To get a playable URL, you can use this id from the response to query the Graph API like this:
/{video_id}?fields=source
Have a look at https://developers.facebook.com/docs/graph-api/reference/v2.1/video/

Posting data from android app on my Twitter's account as tweet

I'm trying to post my data through android app on my twitter account so how should i do it.
i have tried a way, below is the code, and in that it is showing the data on my account and i need to click on the tweet button to get it tweeted. So can i know how to post it directly without asking me to tweet. Like Four Square app
public void open(View view){
String text = "Share Your Experiance ....!!!";
String url = "twitter://post?message=";
try {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url + Uri.encode(text)));
startActivity(i);
} catch (android.content.ActivityNotFoundException e) {
Toast.makeText(this, "Can't send tweet! Please install twitter...", 2).show();
}
Thanks in Advance !!!
Firstly you have to check are you logged with twitter or not after as your condition you can apply this snippet code.
I think you follow the all basics for twitter integration in your code.
public void uploadPic(String message, String getImgUrl)
throws Exception {
try {
System.out.println(" ON UPLOAD PIC FUNCTION getImgUrl "+getImgUrl);
// URL url = new URL("http://faveplatewebservice.siplstudio.com/uploads/big_dish/oooo14n7464rO4_thumb.png");
URL url = new URL(getImgUrl);
URLConnection urlConnection = url.openConnection();
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
StatusUpdate status = new StatusUpdate("Check Out FavPlates on appstore, which offers you to add and find exciting dishes near you. "+message);
//status.setMedia(file);
status.setMedia("Check Out FavPlates on appstore, which offers you to add and find exciting dishes near you. "+message, in);
mTwitter.updateStatus(status);
} catch (TwitterException e) {
Log.d("TAG", "Pic Upload error" + e.getExceptionCode());
throw e;
}
}
hope it will help you!!
If you stuck anywhere then inform me.
Thankss!!

Android twitter tweet with image [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Can we post image on twitter using twitter API in Android?
I am working in an android application and I want to tweet a message and a picture to twitter. I am able to tweet only tweets to twitter by the code :
String token = prefs.getString(OAuth.OAUTH_TOKEN, "");
String secret = prefs.getString(OAuth.OAUTH_TOKEN_SECRET, "");
AccessToken a = new AccessToken(token, secret);
Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(Constants.CONSUMER_KEY,
Constants.CONSUMER_SECRET);
twitter.setOAuthAccessToken(a);
try {
**twitter.updateStatus("New tweet");**
twitter.//Which property of twitter should I use to tweet an image and //message
} catch (TwitterException e) {
// TODO Auto-generated catch block
Log.e("Errorssssssssssssss", e.toString());
}
How do I include an image as well?
refer to http://www.londatiga.net/it/how-to-post-twitter-status-from-android/, use twitter4j library
public void uploadPic(File file, String message) throws Exception {
try{
StatusUpdate status = new StatusUpdate(message);
status.setMedia(file);
mTwitter.updateStatus(status);}
catch(TwitterException e){
Log.d("TAG", "Pic Upload error" + e.getErrorMessage());
throw e;
}
}
where mTwitter is an instance of Twitter class
Make sure you are using latest version of twitter4j-core jar file.
U can try example which comes with Twitter4j Library.Following code will help u
public final class TwitpicImageUpload {
/**
* Usage: java twitter4j.examples.media.TwitpicImageUpload [API key] [message]
*
* #param args message
*/
public static void main(String[] args) {
if (args.length < 2) {
System.out.println("Usage: java twitter4j.examples.media.TwitpicImageUpload [API key] [image file path] [message]");
System.exit(-1);
}
try {
Configuration conf = new ConfigurationBuilder().setMediaProviderAPIKey(args[0]).build();
ImageUpload upload = new ImageUploadFactory(conf).getInstance(MediaProvider.TWITPIC);
String url;
if (args.length >= 3) {
url = upload.upload(new File(args[1]), args[2]);
} else {
url = upload.upload(new File(args[1]));
}
System.out.println("Successfully uploaded image to Twitpic at " + url);
System.exit(0);
} catch (TwitterException te) {
te.printStackTrace();
System.out.println("Failed to upload the image: " + te.getMessage());
System.exit(-1);
}
}
}
Download Twitter4j Library look for more examples there.

sharing a photo to twitter from an android app

in my app i am showing some photos which are uploaded to our local server. If the user likes the photos he can share it to twitter and thru email.
Is there any way to share a image to email when it is been stored in an url.
Following is my twitter code
Intent i = new Intent(getApplicationContext(), PrepareRequestTokenActivity.class);
i.putExtra("imagetitle", imgtit);
i.putExtra("image_path", get_intent_path );
startActivity(i);
how could it be shared to a twitter wall
You can use twitter4j and can share photo and text. A sample code is given bellow.
public void Share_Pic_Text_Titter(File image_path, String message,
Twitter twitter) throws Exception {
try {
StatusUpdate st = new StatusUpdate(message);
st.setMedia(image_path);
twitter.updateStatus(st);
} catch (TwitterException e) {
Log.d("Error==>", "Pic Upload error" + e.getErrorMessage());
throw e;
}
}

Categories

Resources