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

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!!

Related

Upload audio url in twitter 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();
}

Sending a String result to a website

I'm rather new to Android Dev and I'm stuck at the very last part of my app. I've made a barcode scanning app (thanks Zxing) and would like to search the result on a website.
So for example if I wanted to search my result on www.trademe.co.nz how would I go about doing this?
So far I've gotten the String and opened the browser I just don't know how to import the text into the right textbox and search it.
The web part of my code.
private void openBrowser(String contents, String format) {
Intent i = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.trademe.co.nz"));
startActivity(i);
}
Sorry if I've done something wrong, this is my first post!
Thanks is advanced for any help :)
Try this (and mark this as an answer if my answer solve your problem)
private void openBrowser(String contents, String format) {
String url = "http://www.trademe.co.nz/Browse/SearchResults.aspx?searchType=all&searchString=%s&rptpath=all&type=Search&generalSearch_keypresses=5&generalSearch_suggested=0";
try
{
your_keyword = URLEncoder.encode(your_keyword, "UTF-8")); //encode keyword
}
catch (UnsupportedEncodingException e)
{
e.printStackTrace();
}
url = String.format(url, your_keyword);
Intent i = new Intent(Intent.ACTION_VIEW,
Uri.parse(url));
startActivity(i);
}
Use httpPost method to post your string to the url.
Check
here
Also see a simple example here

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;
}
}

fbShare in android

Can anybody suggest a good method for creating a facebook share implementation for my application.
I have created the test account and API key for the facebook developer site...
I need to implement in such a way that,when the fbshare button is clicked,a particular content(dynamic content) should be posted as a status link in the corresponding linked facebook account...
Apart from the fb developers,i need some other way of implementing it...
Suggestions expected...(possibly better results expected)
Hi use this method in your code in facebook handler class
public void postToFBWall(final String message, final String image){
Thread thread = new Thread(){
public void run(){
try{
String descripton = "This is the plain text copy next to the image. All work and no play makes Jack a dull boy.";
Bundle parameters = new Bundle();
parameters.putString("message", message);// message to be posted on facebook wall
parameters.putString("link", image);//link of image to be posted on facebook wall
parameters.putString("name", "My wish");// name of link
parameters.putString("description", descripton);// description of you post
String response1 = facebook.request("me/feed", parameters, "POST");
Log.v("facebook response", response1);
}catch (Exception e) {
}
}
};thread.start();
}
Try this one
https://developers.facebook.com/docs/mobile/android/hackbook/
it may helps you.

How to Integrate Twitter Oauth as like Facebook?

I am new to integrating Twitter. I have implemented Twitter in my application with this code:
// Create file
File picture = new File(APP_FILE_PATH + "/myAwesomeDrawing.png");
// Create TwitPic object and allocate TwitPicResponse object
TwitPic tpRequest = new TwitPic("username", "password");
TwitPicResponse tpResponse = null;
// Make request and handle exceptions
try {
tpResponse = tpRequest.uploadAndPost(picture, "Image Uploaded from My AndroidDrawing App...");
}
catch (IOException e) {
e.printStackTrace();
}
catch (TwitPicException e) {
e.printStackTrace();
}
// If we got a response back, print out response variables
if(tpResponse != null)
tpResponse.dumpVars();
All works fine here. But here I have to add the username and password programmatically. Is there any other way to use the Twitter integration as like Facebook OAuth to integration?
I need to know how Twitter OAuth is checked, and if the User is not login then it will ask for the username and password in its in built window.
If caguilar187's code link's are not enough, then here are few more links for code help:
http://blog.doityourselfandroid.com/2011/08/08/improved-twitter-oauth-android/
http://blog.doityourselfandroid.com/2011/02/13/guide-to-integrating-twitter-android-application/
http://marakana.com/forums/android/examples/312.html
Best suggested: http://android10.org/index.php/articleslibraries/291-twitter-integration-in-your-android-application
One more suggest: http://automateddeveloper.blogspot.com/2011/06/android-twitter-oauth-authentication.html
Post on Twitter: http://www.londatiga.net/it/how-to-post-twitter-status-from-android/
GitHub Link: https://github.com/brione/Brion-Learns-OAuth
Hope below link help you:-
Below link show you how to generate key with Twitter and other social media
http://code.google.com/p/socialauth-android/wiki/Twitter
Now below link is source code where u find out source code
http://code.google.com/p/socialauth-android/downloads/list
here are a few they all use signpost to do it.
Signpost:
http://code.google.com/p/oauth-signpost/
Blogs
http://dev.bostone.us/2009/07/16/android-oauth-twitter-updates/#awp::2009/07/16/android-oauth-twitter-updates/
http://blog.copyninja.info/2010/09/android-oauth-authentication-with.html
http://code.google.com/p/oauth-signpost/wiki/TwitterAndSignpost

Categories

Resources