I would like to integrate Twitter into my Android application so that I can post messages to Twitter.
It really depends on how you want the interaction to work. You can:
Use their API (helped by a library such as twitter4j, as suggested by Heiko Rupp), or
Find a way to integrate with the Twitter app, although there is no published protocol for this as far as I know. This is also not a good idea because many people use other apps such as Twidroyd, TweetDeck and so on, but it would definitely be cool, or
If you don't expect the user to do this very often, you can just open up http://twitter.com/?status=<what-to-tweet> using a simple intent.
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 a few known apps (official Twitter, TweetDeck, ...) and if all of them fail (because they're not present or because they have been updated and broke the protocol) you resort to opening up the browser.
Also note that it might be possible for method 3 to actually launch an app instead of the browser (or at least give the user a choice between the two), if the app handles the correct intents.
Another thing worth mentioning is that it's very possible that you will not be able to integrate with any Twitter apps. What I've said here is purely hypothetical, I have no idea whether these apps support such integrations. You should consult each app and see if they expose some intents that you could use. If they don't, you can still hack around a little and you might find them, but that will be unreliable because they will most probably break after a couple of updates.
You could use the twitter4j library to talk to twitter. Since Twitter has changed over to oAuth, the initial authentication is not trivial.
Basically you need to register your app with Twitter (go to your profile and then to the developer page to register your app - you will then get consumer token+secret). Then follow this example to authenticate with Twitter.
You may have a look at Zwitscher (rev 0.65, code of oAuth has not been updated for the nw internal changes after 0.65), which is an open source Twitter client for a larger example.
You may have a look at one of my examples of how to get Sign-in with twitter working on android.
It uses twitter4j, and with slight modification, you can make it post tweets too!
find it here.
UPDATE: there's one question specific to this issue: twitter,update status
I use twitter4j and oauth-signpost to create facebook like oauth authorization (webview dialog). Checkout this post
You can send the appropriate Intent to start the default twitter application
You can do this without Twitter4j, thus avoiding the massive headache of implementing the OAuth flow.
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 are listed here.
If the user has the Twitter App installed on their device it'll open it directly to a share view. When cancelled or shared it'll return direct to your App. Super simple. Similar to how iOS handles sharing now (with Facebook and Twitter integration).
This doesn't handle cases where the user uses another App as their primary Twitter client.
Related
I want to enable users to share a URL+ text with a WhatsApp group. I want this to work both from iPhones and Androids. However my app is in a browser (it's a website). I'm currently looking into 2 options, but both have issues:
1) The first potential solution - sharing directly from the browser.
I checked out WhatsApp's URL schema and used the following URL to share through my app:
"whatsapp://send?text=Hello%2C%20World!"
However there were several problems with this approach:
It seems to work only with iPhones and not with Androids. Is there a comparable solution somewhere for Androids?
It enables to choose who to send to only after you are redirected to WhatsApp, unless you know the address book ID (=abid) of the user. First, I do not know how to access the abid of users? Second, I am trying to send to a group, in which case there is no abid (right?), and therefore it seems impossible to do this. Is that true?
Also, what happens for Android apps? What is the comparable to the abid, for a group, and how do I get it?
2) The second potential solution - creating a native app which is identical with the browser-based app, but this specific part (where we do the "sharing") is native.
However, it seems to me that in this case I have very similar problems to the ones described above:
I can see how to do this for iOS on WhatsApp's website (see the link above). However, does the WhatsApp URL schema work with Android native apps as well?
Again, the address book ID issue is the same. How do I get it? It may be easier to get the abid on iOS given that we are now a native app, but does it exist for a group? And how about the Android app? Would this share to WhatsApp group work there?
Sharing directly from the browser works both in iPhone and Android if you use WhatsApp version 2.11 or higher. As you said it DIDN'T USED TO work in Android.
U can use the same URL
"whatsapp://send?text=Hello%2C%20World!"
Knowing abid is not possible as far as I know.
Hope this was helpful.
Thank You.
in Android you can invite friends from an app using Intent, see the following Code
final ComponentName name = new ComponentName("com.whatsapp", "com.whatsapp.ContactPicker");
Intent oShareIntent = new Intent();
oShareIntent.setComponent(name);
oShareIntent.setType("text/plain");
oShareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Your Message");
startActivity(oShareIntent);
I hope this solves your problem
I managed to post status updates on facebook walls and log in via the following code:
facebook.authorize(this,
new String[]{ "publish_checkins", "publish_stream"},
new DialogListener() { /*crazy stuff here*/ }
);
My problem is the very first time logging in. Because it seems that the facebook is is not supporting logins from test accounts I can't talk about SSO but consider the "normal", web based, login screen popping up.
Is there a way get around this screen and let the application perform a login via username/email/password combination - provided the user is willing to handle this data to the applications.
E.g. something like facebook.authorize(this, permArray, userName, password,
I ask because I'm not sure if this is even possible at all, read: if fb API is providing hooks for this. I can imagine it is kinda security concern and thereby switched off.
In this case it would be cool if someone could provide a link to some documentation listing all possible login methods (not "all" but the important ones for smartphones) - this would definitely be helpful in the next meeting.
The main document one should work with, in my opinion, when implementing the Authentication part for FB, is their tutorial (for Android this one) - seems you're familiar with it. There you can see how facebook expects you to get logged in.
And here (for Android here) is the list of the methods they provide for these purposes.
To be shorter, NO, they don't have some simple function, which would allow you to do something you mentioned. Looks like you must use browser/their official app to login, in order to save cookies there; or you can use UIWebView to save them in your app.
I worked with FaceBook API some time ago and I didn't like it a lot. Perhaps this is because of the changes they've been doing lately in the API, but their documentation seems to be just immature; not speaking about their official example client (HackBook), which just doesn't work as expected (e.g. post video on the wall doesn't work).
Somehow even after reading carefully their documentation I had quite a lot of questions like what can be done with this API and what's forbidden at all.
Hope this helps!
I want to connect my users to signin in facebook through my app. I did some google and some people are saying use fbrocket where as some http://github.com/facebook/facebook-android-sdk.git. I want suggestions
1) which one is easy to implement?
2) what is the difference between them?
3) Why I need to install a jar. Can I achieve this using some Facebook Api?
Any suggestion is much appreciated.
Thanks rachana.
As Cristian said, fbrocket predates the official SDK and is more or less obsoleted by the official SDK, which is newer, shinier, and mostly based on newer longer-support-lived standards like OpenGraph and OAuth. FBRocket is supposedly being rewritten for these, but there's no release for that yet AFAIK. There's a few things the official SDK is still missing (photo uploading, for instance) but if you just want sign-in-via-facebook, it's definitely the way to go.
I'm not sure I understand your 3rd question though -- you need to include Facebook code, either by a jarfile, android library include, or copy-paste -- in order to actually call the Facebook APIs. The Facebook project is open source; if you're not comfortable including it wholesale, you can freely yank out the bits you need. For example, I've used it in projects that only needed authentication and not publishing, customizing the auth dialog handline and removing all the non-login-related code. You could roll your own implementation based on authenticating via OAuth2 and call all the endpoints yourself, but why bother when Facebook already did the work of giving you the code to do that from Android already?
I recommend to use http://github.com/facebook/facebook-android-sdk.git since it's official and it's updated regularly (it's also really easy to implement and it comes with a couple of nice examples). On the other hand FBRocket seems to be out of date, and the developers are still working on the support for Facebook Graph API.
This is facebook's developer info page, the link you gave seems to be the official Android API.
The jar is the actual library that speaks with facebook.
What action on Facebook are you trying to perform? If you are only trying to allow the user to post content from your application to their facebook page you do this
private static final String FACEBOOK_URL = "http://www.facebook.com/sharer.php?u=
try {
Uri uri = Uri.parse(FACEBOOK_URL + yourcontent + "&src=sp");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
catch (Exception e)
{
e.printStackTrace();
}
}
I can't get Oauth to work with Twitter. I have tried the following (all result in the same 401 error):
jTwitter (using the default OauthSignpostClient)
jTwitter using the commonshttp library (CommonsOauthProvider) instead of the "DefaultOauthProvider"
jTwitter using the OauthScribeClient (instead of the OauthSignpostClient)
oauth-signpost (by itself... no jTwitter)
Twitter4J
http://code.google.com/p/agirardello/
http://dev.bostone.us/2009/07/16/android-oauth-twitter-updates/
http://github.com/kaeppler/signpost-examples/blob/master/OAuthTwitterExample/src/TwitterMain.java
I've tried my own implementation and copy/pasted the sample code from each of the sites, and nothing seems to work. I'm also 100% sure I also downloaded and included any dependencies (where needed).
Here's the interesting part. Using jTwitter and the oauth-signpost library, I can initiate a connection to Twitter, open a browser window for the user, have them log-in and generate a PIN for my app. When the app goes to post a status update however, (using the pin, and the stored access token and token secret), the 401 error pops up. All other things I've tried won't even let me open a browser window and ask the user to generate a PIN (they die with the 401 error on the request for the "request token").
Please help. Thanks
I don't know if it will help you much with Android, but this post on Twitter OAuth by Chris Shiflett just came up on my interwebs.
First of all for OAuth you need to register your application with twitter I am assuming you have registered it. Now in case of desktop and mobile application you need request twitter for custom callback URL, as default callback url just works only for web apps. Once twitter approves requested call back URL , it will work .
But there is workaround, rather than OAuth request twitter for xAuth by submitting details of your applications. Then if twitter approves it , you can uses xAuth which works almost similar to OAuth.
Make sure your application had read&write access when you created it....
I need to write an Android application that allows a user to connect to multiple social networking sites like MySpace, LinkedIn, FaceBook etc. and fetch friends list.
I know that most of these applications have Java libraries or functionalities exposed as REST based WebServices. But since there is a lot of variety and disparity in the ways that these libaries are written or service that can be consumed, is there any single, integrated service or middleware component that I can use to provide a unified interface in my mobile application?
What would be the best way to go about writing such an application? Any links or pointers to tutorials and documents would be helpful.
Thanks.
Well, that pretty much depends on the service APIs exposed by these sites. If they're RESTful, it would be easy and straight forward to write the API accessors yourself using the Apache HttpClient implementation shipped with Android.
If you want to make your life easier you may want to look at Droid-Fu's HTTP abstractions, and maybe Signpost, if you require OAuth message signing (which you need for many popular sites like Netflix, LinkedIn, Twitter, ...).
Here is some code that fetches mentions from Twitter using these two libraries:
// configure an OAuthConsumer with Twitter credentials
oauthConsumer.setTokenWithSecret(accessToken, tokenSecret);
// get Twitter mentions for the user identified by accessToken
String endpointUrl = "http://twitter.com/statuses/mentions.xml?since_id=12345";
BetterHttpResponse response = BetterHttp.get(endpointUrl).expecting(200, 404).signed(oauthConsumer).send();
if (response.getStatusCode() == 200) {
... // consume response
}
That stuff worked pretty well for me with the Qype API.
I'm also working on similar project. I'm planning to use some of the excellent framework
an open source api for all social networking site except Facebook - http://wiki.opensocial.org/index.php?title=Main_Page
opensocial for Java Client - http://code.google.com/p/opensocial-java-client/ [Android]
[This is the Open Source FaceBook API for Android]3 - https://github.com/facebook/facebook-android-sdk
the most useful Twitter API - http://twitter4j.org/en/index.html
one of the most popular Twitter API - http://www.winterwell.com/software/jtwitter.php
And this link contains some of the excellent project for social network based android app - http://code.google.com/android/adc/gallery_social_networking.html
Cheers
-Neo