Sorry for the vagueness of my questions here, but I wanted to know if it was possible to login into this website https://oyster.tfl.gov.uk/oyster/entry.do through an a native phone app?
I've seen many apps which access data for the Oyster Card but there is no API for them to access this data and can only think they've logged into the website using the users details then extracting the necessary text to display within their app.
Here is a sample app alongside what the actual website looks like once logged in;
Sure it is, here is an example using WebView:
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("https://oyster.tfl.gov.uk/oyster/entry.do");
webview.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
view.loadUrl("javascript:document.getElementsByName('j_username')[0].value = '"+ausername+"'");
view.loadUrl("javascript:document.getElementsByName('j_password')[0].value = '"+apassword+"'");
view.loadUrl("javascript:document.forms[0].submit()");
}
});
This will show the common desktop version of the website but if you want a dedicated app for the site, it would be preferable with some sort of API for the site. Without an API, you are left with either the common desktop website, or DOM manipulation of the received html using regular HTTP requests.
Related
i have this code to log in to spotify in my app. I using the offical spotify lib.
public void spotifyLoginBtnClicked(View v){
//start the authentication for spotify
AuthenticationRequest.Builder builder = new AuthenticationRequest.Builder(clientID, AuthenticationResponse.Type.TOKEN, redirectURI);
builder.setScopes(new String[]{"user-read-private", "streaming"});
AuthenticationRequest request = builder.build();
// open LoginActivity
AuthenticationClient.openLoginActivity(this, activityIdentification, request);
}
Im wondering now how i can create a logout button. Because once logged in, if i press the login button again, it just returns. So i'am unable to change the user. I havent found anything in the java doc.
I just found this document which looks similar to the code you pasted for logging in.
In there it mentions a few methods for logging the user out but I think the main block of code you will need is:
To log out and clear all stored tokens, use the AuthenticationClient#clearCookies method. Both Spotify and Facebook tokens will be removed.
I would go and check that article I linked above as there is edge cases that might be important for your project.
Happy Coding!
I'm building a web portal by using Java; besides other requirements, I'm struggling my mind one one very simple (at least at first view) requirement:
my customer wants on his portal the first N posts of his facebook wall
and he wants to read the first N tweets of his twitter page
Since my java code is based on Spring, I wanted to use spring social, spring social twitter and spring social facebook in order to satisfy the requirement
With twitter I had no problem; in fact I
created an app on twitter
got twitter app id and app secret
prepared code
In a couple of hours, all worked pretty good
Problems were born with facebook and it's a lot of time I'm fighting with it
I passed from spring social to facebook4j (since this last one seems to me stronger).
I did the following
created an app on FB
got the facebook appId and appSecret
told to the code that I need the read_stream permission
prepared the code
But I'm not able in reading posts from my wall
Is there anyone who was able in satisfying this kind of scenario?
here my facebook4j code
private static final Logger log = LoggerFactory.getLogger(FacebookTest.class.getName());
public static void main (String[] a)
{
try
{
ConfigurationBuilder cfgBui = new ConfigurationBuilder();
cfgBui.setDebugEnabled(true);
cfgBui.setOAuthAppId(myAppId);
cfgBui.setOAuthAppSecret(myAppSecret);
cfgBui.setUseSSL(true);
Configuration cfg = cfgBui.build();
FacebookFactory ff = new FacebookFactory(cfg);
OAuthSupport support = new OAuthAuthorization(cfg);
support.setOAuthPermissions("read_stream");
AccessToken appAccessToken = support.getOAuthAppAccessToken();
Facebook face = ff.getInstance(appAccessToken );
ResponseList<Post> posts = face.searchPosts("test");
for (Post post : posts)
{
System.out.println(post.getId());
}
} catch (Exception e)
{
log.error("Errore", e);
}
}
As far as I understood, I should need the user access token, but I don't know how to generate it; should I create a login flow and show to the user the FB login dialog? If so, why should I create app id and app secret? They have no sense in my scenario
Moreover...in my case...the server side should authenticate on FB and read posts from a well know user wall (the wall of my customer...) so....where should I present the login dialog? where should I redirect after the FB login?
Is there any good man :) who can clarify to me the FB read post flow?
You MUST use one of the possibilities to authorize the user (with read_stream) in order to get access to his stream. Here´s the link to all the possibilities: https://developers.facebook.com/docs/facebook-login/v2.2
You can also generate Access Tokens with the Graph API Explorer: https://developers.facebook.com/tools/explorer/
Detailed information about Access Tokens and how to generate them can be found in the following links:
https://developers.facebook.com/docs/facebook-login/access-tokens
http://www.devils-heaven.com/facebook-access-tokens/
Keep in mind that an Extended User Token only lasts for 60 days, after that your customer would have to refresh it manually. In general, you are not allowed to use User Profiles for commercial reasons, and it´s very unusual to show a User stream on a website.
Better: Use a Facebook Page. /page-id/feed with an Extended Page Token that lasts forever.
If you use spring-social-facebook, you could let the user login via (front-end login flow) and then you can access the users wall. However, user would need to login and authorize your app to perform the operations.
Here is a spring social sample project that demo's how spring-social-facebook login is done https://github.com/spring-projects/spring-social-samples
Also, within your java code you can use feedoperations to gather information about home feed and also query against it. Checkout the documentation.
facebook.feedOperations().
I just implemented the ad-network, Leadbolt, into my android application. Im using the HTML Banner as my adtype. And I would like some kind of fallback solution if Leadbolt fails to load use Admob instead etc.
Bringing Leadbolt html ads is done via a webview and you pass in a URL to the webview and the ad is shown within.
This is the code:
wv.getSettings().setJavaScriptEnabled(true);
wv.setBackgroundColor(Color.TRANSPARENT);
String html = "MY_ID";
wv.loadData(html, "text/html", "utf-8");
I also have set my Webview (wv) set on: setWebViewClient, so I get callbacks but even if I dont have any internet connection I get the callback OnPageFinished so im unable to se if my ad has loaded or what has been done.
Does anyone have any advice how to do this, to help me with a fallback solution?
Thanks!
Check your www.adwhirl.com
With the SDK and homepage you can create new "Apps" with a fallback hierarchy. All you need to do is, create a custom event on adwhirl, implement the method for calling your ads on leadbolt add your publisher id to admob settings and set up the fallback hierarchy.
Hope this helps. Good luck.
I am developing an Android app which takes the current location of the user and displays a list of restaurants close to his/her location. The restaurants' data is available to me (i.e I do have the lat/long of each restaurant I want to display in the search results). I can't use Google Places API, because I need to show only those restaurants that are available in our database(in our website). My question is how do I access my database(or even an URL),which is on a computer, to extract the restaurants' data and display as search results in my android app?
I am actually making a Seamless ( http://bit.ly/Jp7pUN ) type application for my company.
I am a complete newbie to android app development. So, pardon me if this is really a very broad or a stupid question. Please just tell me what topics I need to study to implement this. I would study and do it myself.
Thanks.
You will need:
a Sqlite database to store the restaurants and their longitude/latitude
a MapView to display the map (Don't forget to register your Google Maps API key)
a map overlay to show the markers on the map
GPS access to get the user's location (needs the appropriate Android permission)
a simple search algorithm that retrieves a result set of restaurants within x distance of the user's location
EDIT
If your database is stored on a server, you will need a way to query the server, preferably using an HTTP-based protocol such as REST. It is useful (but not required) to cache the restaurant locations on the Android device (using Sqlite), in case the user is offline (The good news: Since you can use Java both on Android and the server, 90% of your data access layer you will only need to write once).
For the data transfer from server to the Android client, JSON is a popular format.
To acces database on your computer (not SQLite on Android) you should use url for your database server changing localhost to: 10.0.2.2. But in case your database will be on the Internet - you should create maybe some REST API to get the data you need. Then use HttpClient to fetch the data from server.
Everything that you need is in Developer Guide: MapView
And for retrieving current location I advice using MyLocationOverlay
For example (url to server):
//public static final String SERVER_ADDRESS = "http://10.0.2.2:3000"; // for localhost server
public static final String SERVER_ADDRESS = "http://railsserver.herokuapp.com"; //for remote server
Accessing data on your server - this depends on that how you implement (and using what thechnology) your server (REST API?, WebService?, Plain HTML?) and what will be the format of the response from server (JSON? XML?, etc.)
I suggest using JSON because it is easy to parse using included classes in Android SDK:
String json = execute(new HttpGet(Constants.SERVER_URL + "/fetchData"));
JSONObject responseJSON = new JSONObject(json);
if(responseJSON.has("auth_error")) {
throw new IOException("fetchData_error");
}
I was looking through for some solutions to read a file after uploading and I found this:
Read text file in google GWT?
that has a solution of
new RequestBuilder(Method.GET, "path/to/file.txt").sendRequest("", new RequestCallback() {
#Override
public void onResponseReceived(Request req, Response resp) {
String text = resp.getText();
// do stuff with the text
}
#Override
public void onError(Request res, Throwable throwable) {
// handle errors
}
});
It seems to be a feasible solution for my case, but I am kinda new to this, can any one explain how can I apply this in gwt? i have FileUpload placed in a panel already and a click handler to handle the submit button click.
Can someone help me out with this?
The answer you link to is for reading files from the server. They are just requesting the file from the webserver. It sounds like you want to read files from the client (you are using a FileUpload). There are different methods of doing that based on the stack your app is running on and what clients you support.
The GWT FileUpload is just an input control on the form which allows the user to pick a file. It does not do any part of the actual file reading.
A common approach is to send the file as part of the HTML form to the server and then reflect it back to the client to get it into your web app. This site is a little old but is great at giving you the basics of this approach. There are several examples using this with GWT: for example which also links to this. This option has the widest client support, but costs more in network traffic.
If you know the clients support HTML5 you can also read the file in JavaScript using the File API. Here are some docs from Mozilla. Unfortunately, there's not really integrated GWT support for it, so you'll have to write some JavaScript. This option will not be supported by all clients, but also doesn't generate any network traffic.