How to post on twitter wall using twitter integrate Android application

I would like to integrate Twitter into my Android app to post to Twitter.

+4
source share
6 answers

It really depends on how you want the interaction to work. You can:

  • Use the API (helped by a library such as twitter4j as suggested by Heiko Rupp) or
  • Find a way to integrate with the Twitter application, although there is no published protocol for this, as far as I know. It’s also not a good idea, because many people use other applications like Twidroyd, TweetDeck etc., but it will definitely be cool or
  • If you do not expect the user to do this very often, you can simply open http://twitter.com/?status=<what-to-tweet> with a simple intention.

Method 3 can be easily described here:

 Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse("http://twitter.com/?status=" + Uri.encode(message))); startActivity(i); 

You can also combine 2 and 3. You can try several well-known applications (official Twitter, TweetDeck, ...), and if all of them fail (because they are missing or because they have been updated and the protocol), you resort to opening a browser.

Also note that it is possible that method 3 may actually launch the application instead of the browser (or at least give the user a choice between them) if the application processes the correct intentions.

Another thing worth mentioning is that it’s very possible that you won’t be able to integrate with any Twitter apps. What I said here is purely hypothetical; I have no idea if these applications support such integration. You should consult each application and see if they reveal some intentions that you could use. If they do not, you can still hack a little, and you can find them, but it will be unreliable, because they are likely to break after several updates.

+9
source

You can use twitter4j library to chat with twitter. Since Twitter has changed to oAuth, initial authentication is not trivial.

Basically, you need to register your application using Twitter (go to your profile and then on the developer's page to register your application - then you will get a secret token + user). Then follow this example for authentication using Twitter.

You can take a look at Zwitscher (rev 0.65, oAuth code has not been updated for internal nw changes after 0.65), which is an open source client for a wider example.

+1
source

You can take a look at one of my examples of how to get Twitter login running on Android.

It uses twitter4j, and with minor changes you can also send a message to tweets!

find here .

UPDATE: There is one question related to this problem: twitter, update status

+1
source

I use twitter4j and oauth-signpost to create facebook, for example, oauth authorization (web browsing dialog). Checkout post

0
source

You can send the appropriate Intent to launch the default Twitter app.

0
source

You can do this without Twitter4j, thereby avoiding the massive headache of implementing an OAuth stream.

 String tweetText = "We be tweetin!"; 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!", 2).show(); } 

Other supported twitter:// urls twitter:// are listed here .

If the user has a Twitter application installed on their device, it will open it directly for sharing. If canceled or shared, it will return directly to your application. Super simple. Similar to how iOS handles sharing (with Facebook and Twitter integration).

This does not apply when a user uses another application as their main Twitter client.

0
source

Source: https://habr.com/ru/post/1338391/