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
Related
I'm reading about Flask. Given its tight integration with Jinja2 and WTF-forms, what happens when I start writing a native mobile version of my website? I usually write a bunch of backend API that work independent of the frontend and then code up the frontend using JS. This way, if I have to implement a native mobile app, I can seemlessly use the backend APIs. With Flask's (or some other framework's) tight integration with template engines, how should I design my application?
For example, let us take an example from here, the author advocates that the login function be written like this:
from flask import render_template, flash, redirect
from app import app
from forms import LoginForm
# index view function suppressed for brevity
#app.route('/login', methods = ['GET', 'POST'])
def login():
form = LoginForm()
if form.validate_on_submit():
flash('Login requested for OpenID="' + form.openid.data + '", remember_me=' + str(form.remember_me.data))
return redirect('/index')
return render_template('login.html',
title = 'Sign In',
form = form)
However, when I am building a native Android/iOS app, I'm assuming that the backend should expose a bunch of API calls that validate the input and do the login for you. And given that mobile is agnostic to Jinga2 or some other templating (because everything is implemented native), all this code is useless in the context of native mobile apps. This means, I will have to refactor the "real-world" Flask code to be compatible with a mobile app. Is this the case or am I missing the higher-level point?
My specific question is: What is the design pattern I should follow in Flask to ensure that my site is web and mobile friendly?
I think there are 2 issues here:
Writing a web client that is web and mobile friendly
Designing an application with web and mobile components
Issue 1 would involve a responsive web design that formats the webpage in a manner friendly to both desktop web browsers and mobile web browsers. There are CSS techniques to use different style sheets and templates depending on the browser viewport size. This would be where different jinja2 templates could be used for mobile vs. web clients. Or there are "responsive designs" that adjust according to viewport size.
Issue 2 speaks to how you architect your services and clients. You could do like you said and have a backend API (could be a Flask application or not. Flask-Classy or Flask-Restful are Flask extensions that assist in developing REST API with Flask) independent of any frontend. Then you could code a native mobile app that uses the backend API. And you could code a Flask web application that also uses the backend. There wouldn't be any dependencies between the mobile app and the Flask app. They're just two distinct clients that both access the same backend API.
The example you linked to is creating a monolithic web application. It's an excellent tutorial if that's what you're looking to create. But it wouldn't apply in its entirety if you want a set of services that can be used by both mobile apps and web clients.
Well there is a crude way to go about this issue which I used successfully in my application. So every time a request is made from the web application or the android application I add a field in the request called "device" and set its value to "web" or "android" accordingly.
On the front-end:
<form id="test" action="test" method="get">
<input type="hidden" name="device" value="web"/>
<input type="submit" value="Submit"/>
</form>
Similarly I do the same from my Android Application.
Now at the Flask Server I read the value of this field and handle the request accordingly.
#app.route('/test', methods=['GET'])
def test():
device = request.args.get('device')
if device is "web":
return render_template('test.html', data='Hello Word')
else:
# Return data to Android Application
return json.dumps({'data':'Hello World'})
I am pretty sure there must be a much better way to deal with this, but this one works perfectly fine. Hope it helps :)
#Bahul Jain You can get that using the following code. Not sure is this right way or wrong. But you can check platform in your if condition.
from user_agents import parse
browser = request.user_agent.browser
version = request.user_agent.version and int(request.user_agent.version.split('.')[0])
platform = request.user_agent.platform
uas = request.user_agent.string
print('---browser-{}-----version---{}-'.format(browser, version))
print('---platform-{}-------uas-{}---'.format(platform, version))
I am trying to develop a Moodle Android app. I am using MoodleREST source code for my reference.Is there any other documentation on Moodle site which documents moodle core webservice functions with their required params.
I have found list of functions here http://docs.moodle.org/dev/Web_services_Roadmap but could not get proper documentation on how to call these functions with required params from mobile client using REST.
I am new to moodle and still learning it, so my question can be a little naive so please bear with it :)
This could be helpful http://docs.moodle.org/dev/Creating_a_web_service_client
And if you have some administrator access to Moodle, go to
yourmoodle/admin/webservice/documentation.php , or
Administration > Plugins > Web services > API Documentation.
There is API with documentation. (Dont know if there is better way though :/)
D.
AIUI you need admin to access the most comprehensive web service API, as described by #Dolfa. You'll need these docs and/or the source if you're developing against their REST API. The API docs are generated from the source, presumably so they accurately reflect the API in the installed version.
You could:
Browse the code on github
Clone the version you intend to program against so you can browse the code locally
Install it and give yourself admin so you can browse the API docs.
If you don't want to go through the hassle of setting up a local Moodle instance, you may be able to figure out a way to run the php that generates the docs.
Once you have a rough idea of an API call, you can often find out the details by looking at responses to command-line requests e.g.
curl 'https://your.domain/webservice/rest/server.phpmoodlewsrestformat=json' --data 'wsfunction=core_enrol_get_users_courses&wstoken=[your_ws_token]' --compressed | python -m "json.tool"
gives the response
{
"debuginfo": "Missing required key in single structure: userid",
"errorcode": "invalidparameter",
"exception": "invalid_parameter_exception",
"message": "Invalid parameter value detected"
}
indicating that the function requires a userid=[userid] argument.
There is
com.sugree.twitter, java me api
I have used Twitter4j
Click on the following link to get source code
http://automateddeveloper.blogspot.com/2011/06/android-twitter-oauth-authentication.html
You should go for Twitter4j OAuth
OAuth is an open protocol which allows
the users to share their private
information and assets like photos,
videos etc. with another site without
sharing their credentials (username
and password) to the latter. Hence
making it very secure way of
transmission of data..
here is link for this...
http://www.xoriant.com/blog/mobile-application-development/twitter4j-oauth-on-android.html
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.
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();
}
}