I'm working on an android application which logs into a website. Basically I have managed to login within Activity A. The user is then redirected to activity B, I want to maintain that logged in session while in activity B. In order to achieve this I have tried this:
Document postLogin = Jsoup.connect("http://forums.d2jsp.org/")
.cookie("sid", sidDetails.getSid())
.post();
As you can see i'm trying to POST the cookie SID. This obviously isn't working, so does anyone have any ideas on how to achieve this? It should be noted I am using JSOUP.
There's not really enough here to go on. You need to figure out what the site is using to maintain login state, and make sure you're setting up Jsoup to send that data.
What I would suggest is that you use Charles Proxy to trace the requests you make in a regular browser to this site, then make sure you're setting up Jsoup to send the right data. By watching the HTTP traffic over the wire, you'll get a better picture of what's happening, and hopefully spot what's missing.
If you can't see how to get Jsoup to add the right data to the request, just give an example of what you need.
Related
So, I am trying to use GroupMe's API. The issue is that I don't really know how to get the users access_token once I send them to the site to login. I don't really know how to create a callback or how to use it. So to sum it up
I need to send users to this site
https://oauth.groupme.com/oauth/authorize?client_id=CLIENT_ID,
then they login and groupme sends them to here
https://YOUR_CALLBACK_URL/?access_token=ACCESS_TOKEN.
But I don't know how/where to create a callback url. Then I don't know how to send that access_token back to the app.
Thanks.
A callback URL is simply a url exposed by your app that groupme can redirect users to. The page can be anything, however, oftentimes it takes the user back to your app if it is a webapp, or tells the user to close the page.
The important part is that the url is one that the app controls, so that it can get the contents of the url that contain the token and other data.
If you are writing a web app, then the framework or language should a method or variable you can call or read to get the url. If you are writing a desktop/moble app, one way of creating a callback url is to listen on a tcp port and speak http to the browser. Another way is using a lightweight web server library, or use a lightweight external server like lighthttp and communicate using cgi/fastcgi. All that matters is that you can get the url that groupme se,t the user to.
If you need anymore help, you are using Oauth2 so search for help with that. Nothing that you asked about here is specfic to groupme, so you should be able to use any OAuth2 library.
I want to write an app get the information from posts (mostly about new classes) on my university website then make some annoucement once there is new class.
I've google and see RSS mostly, but the page I want to get data does not use RSS. I read something about website using service so we can read XML in the app, but I don't know if the page using service or not. Last resort is using host (somee for example) and js to get text from the page, then the app could read data from the host.
That's all I have right now, but it's still unclear for me. Any suggestion about what to read, what should I use?? Much appreciation
I think the first thing you do should be to ask your uni if they provide any feed or webservice for these data that you could use.
If they don't, or don't answer at all, your last resort would be scraping. To do this, you can use an HTML parser, like jsoup, and then go through the HTML data, getting information as you need.
To see if there are been changes, you would just have to cache your current processed information, probably in a database, and compare the new one to the one currently saved.
My application has to login to a website by posting a form, and keep track of the cookie provided till the application is terminated.
I have achieved this using the "WebView" class. I have doubts on weather this is the most efficient way to achieve this as I do not wish to display any webpages but Simply submitting another form once logged in.
Is their any other solution/Classes that can handle this with less traffic (smaller footprint)?
You can submit data to the login form just as you can to any other.
Using the HTTP library you can add a payload (of type x-www-form-encoded) to a RequestEntity. The JavaDocs are fairly clear on how to do this.
I am trying to interface multiple accounts into a single one. I mean, consider you sell your own stuff at Sites A, B, C, D. I am trying to develop an app, such that the user has to enter his credentials in the settings screen, and from then on, the app automatically logs into each of the site, and parse the HTML to get the balance.
The issue here is, I don't find any API for any of the sites. So Can i open the source of the Login page, and use it to find the HTTP Post URL and the username and password field name tags and use it as normal post? Will it login? Have you ever tried such thing.
You help would be greatly appreciated.
Thanks,
Nithin
Use Firebug in Firefox or (Tools->Developer Tools in CHrome) to find out what is sent as POST parameters & then simulate the same in java.
I wrote a simple script to send SMS using a website and wrote on howto simulate logins. You can have a look at it here. It uses python but gives an idea of how is it done.
I'm in the process of building an Android application that interacts via a JSON API with my website. I've basically got everything together except for user registration on the app. I have an idea on how I want to implement it, but I want to see if there might be an easier way.
My approach is:
When the RegisterActivity is started, display a loading indicator, and make an asynchronous JSON request (via google-gson) to the server get all the fields needed for registration.
When the listener receives a response, populate the spinners, checkboxes, etc. with the possible registration field values.
Allow the user to complete the form and submit via JSON.
You're probably thinking, "Why don't you just store the possible registration spinner/checkbox values in the app itself?" The possible values for each field will be changing over time as I continue to test/push the product, and I don't want to break a build simply because I added/removed some possible options on the server. This is why I'm dynamically building the form based upon a JSON request.
Given that, I'm wondering:
Am I thinking about this the wrong way?
If this is a good approach, is there a JAR or sample implementation someone has out there that already accomplishes this?
You could always just use a WebView and have your registration page written in HTML and hosted on your server. That simplifies things dramatically.
http://developer.android.com/guide/webapps/webview.html