So the site that Im targeting works like this:
The sites name is https://masterbattlerite.com/. https://masterbattlerite.com/ works like this:
Enter username in search bar of the site
Press the search button (or hit enter)
The site directs you to the userpage with the username you entered.
the URL is now something like https://masterbattlerite.com/238338348
that number (238338348) is the id of the user
I want to know how to get that id as a string in my app
I found out of Selendroid but you need some sort of server to be able to emulate a browser? My app will be released on the play store so I don't want my users needing to start their own selendroid server everytime to do this (maybe Im wrong)
In your code, can you use an HTTP library/framework and POST to the same location the site posts to and retrieve the id from the redirect the server sends? You may have to set some extra (possibly hidden on the webpage) parameters to get it to work.
EDIT: ok, it's even easier with the site you mentioned... if you search for a username of bob, you just GET this URL: http://masterbattlerite.com/profile/bob/lookup
and it returns some nice JSON with the id in it like so: {"status":"success","player":{"id":1268,"user_id":"5688","name":"bob","title":504,"avatar":30016}}
BTW - I figured all of this out using the Chrome developer's tools. Learn to use it - it is your friend.
Related
I was playing around with youtube api samples that they provide in this link
with JAVA
I can search for videos upload videos to specific channel and all the code that they provide works fine.
the only problem I face is "when I try to upload it opens my default browser and asks me to sign in"
like this screenshot.
here is what in my head I know it's not that simple it's just a imagination of what I want to achieve.
// String myaccount = "username#gmail.com"
// String mypassword = "123456789"
// String mychannel_id = "UCU7mv98lde1hon2DXIgGMKg"
// signin(myaccount,mypassword,mychannel_id);
// upload(video.mp4);
what I have:
client_id, client_secret in json file
the channel id, account, and the password
i was searching for about a day and all i got is ..
access token
,Token Service API
,identity toolkit api
,onBehalfOfContent,onBehalfOfContentOwner
however I don't know how they work or where I can get them
finally I have small idea I traced the code and I found it saves a file with all credentials in C://users/user-name/.oauth-credentials
it's not readable but it seems like it is used to authorize the account with the password and channel id
can I use this?
would it expire for any reason and i have to refresh and if so how can I refresh it?
thanks for help BTW
I need to pass data to my URL to get the data.
I have done like this...
document= Jsoup.connect("MYURL").data("PASSCODE", "001100").post();
System.out.println(document);
but I am not getting proper output
Need help. I have check this Links also
This and this also.
Usually login into a web site requires two steps:
You send a get request to get the page, and you extract from there some values like session ID etc, and the cookies.
You send a post request with the values from step 1, and your user name and password.
To know which values you need to send, use your browser in the developer mode (by pressing F12) and examine the traffic.
If you want to write an android app, change the user agent string to match your browser, since some sites send different pages to different clients.
You can see an example HERE.
I have a strange re-occurring problem with requests being made to j_spring_security_check via GET method.
All my login forms use POST to j_spring_security check for posting login credentials. Yet, application users reported on several occasions that sometimes they get an error page when trying to log in. I tracked those situations in the logs and it looks like people visit the login page and then next request is GET to j_spring_security_check.
It happend to me once too, but I cannot reproduce it.
Do you have any ideas why this may happen? Could spring security redirect to j_spring_security for some reason?
I double checked html and javascript there are no mentions of j_spring_security_check except in the action field of form elements which all have method set as POST.
Any help or ideas would be appreciated.
EDIT: additional information:
WebApp is served by Tomcat. There is Apache reverse proxy in front of it. Pages that contain login forms pass w3c validations.
After almost a month, we have finally figured out why this thing happens in google Chrome.
Apparently, if you submit a form using SHIFT+ENTER Chrome will open a new window and make a GET request instead of a POST request. Since some users have uppercase characters / special characters as a last letter of the password they type in the last letter with shift pressed and the press enter to log in while not yet releasing shift key. And the result is GET request to j_spring_security check. We will fix this by intercepting shift + enter in javascript.
I'm using the jQuery Address library to re-write my URL depending on what the user is doing in the page. The intention is to allow users to bookmark pages and come back later. The page never refreshes as all server interaction is done via ajax.
jQuery Address is writing URLs like this:
http://localhost:9000/#/u/scott_tiger
I need a to set up a route in Play to be able to route that request through to the appropriate controller. So I set this up:
GET /#/u/{username} Controller.showUser
This doesn't work though, the route definition gets ignored. I've tried loads of things such as trying to escape the "#" and replacing it with a variable that I've populated with Character.toString(35). None of this works.
Does anyone know how I can either define the route properly or get jQuery Address not to write the "#".
EDIT: The "#" doesn't get sent to the server does it. Doh! OK, question is revised.
No. The # and the part of the URL after that is not sent to the server. So your play app on the server will never see such URLs.
HTML5 solution
You need to handle these URLs on the client side using JavaScript. In modern browsers with good HTML5 support, you can modify the address without reloading the page. See Manipulating the browser history on how to do it for these browsers. And see When can I use... for browser support.
#-URLs
On Internet Explorer and older versions of other browsers you need to use # URLs and use JavaScript to load the state (e.g. get the user page /u/scott_tiger in your example). See How to run a JavaScript function when the user is visiting an hash link (#something) using JQuery? for how to do this in JavaScript. Also if a user bookmarks a page with a #-URL you need to reload the state.
See also: What's the shebang/hashbang (#!) in Facebook and new Twitter URLs for?
JavaScript libraries
You may use JavaScript libraries to handle this for you history.js is an example. Also bigger frameworks like Backbone.js handle this.
Does anyone know how I can get jQuery Address not to write the "#".
If you don't write the #-part of the URL, the state can not be linked. So you can not get back to e.g. Scott Tigers profile page if you bookmark the page, because the URL is only http://localhost:9000/ and you will arrive on the front page, while the user though he would arrive on the profile page.
Armed with my new understanding of URLs (thanks #Jonas) I realised that I'd missed half of the story.
I'm using JQuery Address to change the URL depending on what you click in the application. This works great and on lots of browsers. What I was missing was using JQuery Address to watch for external address changes (bookmarks, history, back/forward) and respond accordingly. i.e. set the page up correctly by firing the appropriate Ajax calls and rendering that data appropriately.
Changing the address
$.address.title("new title describing application state");
$.address.parameter("q", "val1");
$.address.parameter("g", "val2");
$.address.update();
Restoring the state
$.address.externalChange(function(event) {
var val1 = event.parameters["q"];
var val2 = event.parameters["g"];
// do something with those values
});
Is there any way of changing gmail password programmatically using java?
The google provisioning API guide has updateUser method which takes a UserEntry object. You can use it to update the password I suppose, you will have to try it out. Check the javadocs for definition of UserEntry
I would have been very surprised if you could, and it doesn't look like it.
This page shows you the list of settings you can change in the Google Apps "Email Settings API", and change-password isn't there.
http://code.google.com/googleapps/domain/email_settings/developers_guide_protocol.html#GA_email_settings_api_ops
HTH
I think yes. You can record all operation with web pages by Selenium, test if all ok, and after export to java code - only problem can arise if Google will use CAPCHA
Uh, just use an http client to post this web page: https://www.google.com/accounts/b/0/EditPasswd. Use http://hc.apache.org/httpclient-3.x/ or something similar. You'll need to keep track of cookies properly, so google thinks you are logged in when you load the page. But yeah, obviously it is possible. If your browser can do it, you can do it programmatically through sending http requests. If you want to be double careful, you can use something like tamperdata in firefox to sniff exactly what your browser sends when you request a password change, so you don't miss any silent fields or whatnot.
Using Google Provisioning API, to change the password, you have to set it to login attribute of UserEntry object:
import sample.appsforyourdomain.AppsForYourDomainClient;
...
AppsForYourDomainClient client = new AppsForYourDomainClient(email, password, domain);
UserEntry user = client.retrieveUser("username");
user.getLogin().setPassword("newpassword");
client.updateUser("username", user);