Error:Cannot access the calendar you requested - android

When I post my events' xml file to google's server , sometimes I will receive the html below , I am very confused why it happens ,but sometimes it is OK. Any one can help me?
Is it caused by the connection error? or the token is invalid ? or what?
<html><head><meta http-equiv="content-type" content="text/html;charset=UTF-8">
<title>Error</title>
<style type="text/css">body {font-family: arial,sans-serif}</style></head>
<body text="#000000" bgcolor="#ffffff"><table border="0" cellpadding="2" cellspacing="0" width="100%"><tr><td rowspan="3" width="1%" nowrap><b><font face="times" size="10"><font color="#0039b6">G</font> <font color="#c41200">o</font> <font color="#f3c518">o</font> <font color="#0039b6">g</font> <font color="#30a72f">l</font> <font color="#c41200">e</font></font> </b></td>
<td> </td></tr>
<tr><td bgcolor="#3366cc"><font face="arial,sans-serif" color="#ffffff"><b>Error</b></font></td></tr>
<tr><td> </td></tr></table>
<blockquote>Cannot access the calendar you requested</blockquote>
<p></p>
<div style="background:#3366cc; width:1px; height:4px"></div></body></html>

Well, I can't say I really like the answer to this question, but I was having the same issue and found an answer after a bit of finagling.
Google has its own session ID that it uses for these kinds of requests. The first time you make a request, it starts the session and gives you a redirect; it also causes the error you saw above. From what I can gather, if you try the request again after the session ID has been set, the request will go through.
In other words, you have to send the request and check the response from Google to see if you're being redirected. If you are, you have a couple of options to grab the URL that has Google's session ID (gsessionid) included; I chose to parse the Location header out of the response, which shows the URL to which the data should be posted. Try your request again (and any subsequent requests) by posting to that new URL, and it should work like a charm. Just takes a bit to get there.
For more info about this, check the Google documentation on redirects and this somewhat related StackOverflow question.

Related

Android Robotium solo - how to access WebElements contained in an IFRAME?

Scenario:
I'm using Android Robotium Solo (v5.6.3) to automate web page interactions within my app. I need to automate data entry into INPUT fields that are contained within an IFRAME but I do not have much luck!
The Problem:
When I attempt to use, for example, solo.waitForWebElement(By.id("room-number", 5000, true) and solo.typeTextInWebElement(By.id("room-number", "101"), solo is unable to locate the element.
The discussion on this related issue "Accessing an iFrame inside a WebView #794" (https://github.com/RobotiumTech/robotium/issues/794), suggests that it's possible to use "solo.getConfig().webFrame = XXX" to focus solo on the content of a specific IFRAME and then access the WebElements. Unfortunately, I've not been able to get it to work and haven't been able to find any full examples. I assume XXX might need to be the "id" of the IFRAME but in my scenario (where I don't have control of the source code for the web pages being automated) the IFRAME tag has no id assigned.
I've created a simple example test scenario:
index.html - the main page that hosts the IFRAME
<html>
<body bgcolor="#AA3333">
<div id="wrapper">
<iframe src="embed.html" width="100%" height="100%" frameborder="0"></iframe>
</div>
</body>
</html>
embed.html - the source for the IFRAME that contains the INPUT element.
<html>
<body bgcolor="#3333AA">
<div id="page-container" style="height:100vh; width:100%;">
<label>Room Number</label>
<input type="text" name="ROOM_NUMBER" id="room-number">
</div>
</body>
</html>
After reviewing the source code for Robotium in more detail I confirmed that using
solo.getConfig().webFrame = ['id' of IFRAME as a String]
allows subsequent calls to solo.typeTextInWebElement etc. to work OK as expected.
The trick in my scenario is that the parent page assigned no id to the IFRAME so I programatically assign one at runtime using the following javascript
document.getElementsByTagName("iframe")[0].id = "test";
and then use
solo.getConfig().webFrame = "test"

JSoup not showing all the html in Java (td and tr tags missing)

I'm having trouble getting all the html code under the tags. Here is my current code:
Document document = Jsoup.connect("http://stackoverflow.com/questions/2971155/what-is-the-fastest-way-to-scrape-html-webpage-in-android").get();
Elements desc = document.select("tr");
System.out.println(desc.toString());
It's for that question, and I'm trying to get the text from the question's description. But I'm getting not getting certain tr or td tags like the ones for the question. Here is td tag I'm trying to get:
<td class="postcell">
Under that tag is the actual post. Now when I print out what I'm actually getting, I'm getting a ton of empty td tags and some comments, but not the actual post.
<tr id="comment-37956942" class="comment ">
<td>
<table>
<tbody>
<tr>
<td class=" comment-score"> </td>
<td> </td>
</tr>
</tbody>
</table> </td>
<td class="comment-text">
<div style="display: block;" class="comment-body">
<span class="comment-copy">You shouldn't parse HTML with regexes: blog.codinghorror.com/parsing-html-the-cthulhu-way</span> –
﹕ motobói
And it keeps on going with empty td and tr tags. I can't find the actual question. Anyone know why this is happening?
Essentially, I just want the text from the question's post, and I don't know how to get it, so it would be nice if someone could show me how to get the text.
Jsoup is a parser. That means that it can't execute any javascript code, that could generate html. When you encounter this problem the only way to retrieve that content is through a headless browser, that includes a javascript engine. A popular library is selenium webdriver.
In order to determine if the content you are trying to parse is generated in the server (static content) or in the client (dynamic content-javascript generated) you can do the following:
Visit the page you want to parse
Press Ctrl + U
The steps above will open a new tab that contains the content that jsoup receives. If the content you need is not there, then it's generated by javascript.
Follow the steps and search for the content. If it's there, but jsoup still has problems, then most probably the case is that the site considers you a bot or a mobile device. Try setting the userAgent of a desktop browser and see what happens.
Document document = Jsoup.connect("http://stackoverflow.com/questions/2971155/what-is-the-fastest-way-to-scrape-html-webpage-in-android").userAgent("USER_AGENT_HERE").get();
Most importantly, when the site exposes and API for the users to extract information programmatically then it's better to just use that.
Stackoverflow has an API available

Submitting a GET to a form with Jsoup in Android

I am attempting to "simulate" a button press and form submission with username and password to sign into the website with source below. I have already tried this:
Document con = Jsoup.connect("http://www.twinrinks.com/adulthockey/subs/subs_entry.html")
.data("subs_data1",autoLogInUsername)
.data("subs_data2",autoLogInPassword)
.post();
(autoLogInUsername and autoLogInPassword are String objects)
But that does not seem to want to work correctly. I have read around here on stack overflow, and I have tried many of the suggestions, but I can't seem to get this to work. I'm thinking my problem is either that the form is a GET instead of a POST, or that i'm not doing anything with the submit button (but I don't know how to reference it because it has no name). Thanks for your help!
<html>
<head>
<title>Login Page</title>
<FONT FACE="ARIAL" SIZE="5" color="#FF00FF">Twin Rinks Ice Pavilion, Inc. Attendance & Subs Program<BR></font>
</head>
<body onLoad="document.forms.myform.subs_data1.focus()">
<form name="myform" method="GET" action="subs_entry.php">
Username:<input type=text name=subs_data1 size="70" value="">
(your email address)<br>
Password:<input type=password name=subs_data2 size="25" value=""><br>
<input type=submit value="Login!">
<br><br>Leisure next session
schedule is done.<br>Bronze next session schedule is done.<br>Silver
next session schedule is done<br>Gold
next session schedule is done.<br>Platinum next session
schedule is done.</form>
</body>
</html>
You can place GET information directly in the URL of the website you're accessing. POST would be harder, but you aren't dealing with that.
For example, if you wanted to send the variables x=3 and y=4 to foo.com/index.html you could simply call
http://www.foo.com/index.html?x=3&y=4

android HTTP post multipart

Hello, I have a website part described as below:
<div id="insertA">
<form class="MultiFile-intercepted" enctype="multipart/form-data"
method="post" onsubmit="return checkAnomalyFields();"
action="dodajN.html">
<table style="border-weight: 0px">
<tbody>
<tr>
<tr>
<td id="wybory"><select id="typ" onchange="typeSelected()" size="1"
name="typuId">
</td>
<td>
</tr>
<tr>
<td>Szerokość: <input id="szer" type="text" onchange="setMarker()"
value="" name="szer">
<div id="szerErr" class="err">Proszę podać szerokość na terenie
Polski (49-55).</div>
</td>
<td>Długość: <input id="dlug" type="text" onchange="setMarker()"
value="" name="dlug">
<div id="dlugErr" class="err">Proszę podać długość na terenie
Polski (14-25).</div> <input id="id" type="hidden" value=""
name="id">
</td>
</tr>
I want to make a HTTP POST request to send data from my client and put it into forms.
I am doing this as follows:
try {
HttpClient client = new MyHttpClient(Send.this);
String postURL = "url";
HttpPost post = new HttpPost(postURL);
//FileBody bin = new FileBody(file);
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
//reqEntity.addPart("myFile", bin);
reqEntity.addPart("typuId", new StringBody("1"));
reqEntity.addPart("statusuId", new StringBody("2"));
reqEntity.addPart("szer", new StringBody("52.321911"));
reqEntity.addPart("dlug", new StringBody("19.464111000000003"));
reqEntity.addPart("opis", new StringBody("jakis opis"));
post.setEntity(reqEntity);
HttpResponse response = client.execute(post);
HttpEntity resEntity = response.getEntity();
AlertDialog.Builder alert=new AlertDialog.Builder(Send.this);
alert.setTitle("Niepoprawne dane").setMessage(EntityUtils.toString(resEntity)).setNeutralButton("OK", null).show();
if (resEntity != null) {
Log.i("RESPONSE",EntityUtils.toString(resEntity));
}
} catch (Exception e) {
e.printStackTrace();
}
The problem is when I read the response I get the HTML code of the site that I am requesting without a success code or anything similar. It looks like I am requesting for site content, but not submitting the form. Any idea what I am doing wrong?
You're submitting to a .html file. Generally servers aren't configured to treat those files as scripts, which means the data you're submitting is simply ignored and dumped. To handle a form submission, you have to submit to a script or other program specifically designed to handle that submission, e.g. a php script.
OK, to clarify what Marc B said: action="dodajN.html" is almost certainly wrong. I've never seen a web server that lets you do this (of course, anything is possible). It should probably be action="cgi-bin/something" or something like that.
It's actually not that important however, since your app isn't using the action clause anyway, but rather writing to "url" which is even more wrong. If you would tell us exactly what url you're really writing to, it might help.
But ultimately, the way you debug this is to look at the server logs and see what's happening at that end.
As a general rule, when I'm developing something like this, I first write the server-side cgi script and a web page to use it. Once my API is working through the web page, only then do I start trying to call the cgi script from an Android app.
My debugging process consists of: 1) Reading the server logs. 2) Having my cgi scripts write their own debug logs. 3) Having my android app dump the response code and headers to logcat.

Input error with keyboard on Galaxy S2 using jQuery Mobile and Phonegap

We are developing a mobile web app in jQuery Mobile 1.0.1 and Phonegap 1.4.1 and have run into issues with the keyboard on the galaxy s2.
We have a menu which slides out and contains a search input:
<input type="search" placeholder="Search..." name="search" id="menu_search" data-role="none" />
When we tap in the input so that it gains focus, the keyboard opens but does not allow us to type anything in. I guess a clue here is that its giving us a regular text keyboard and not the search keyboard (which has a magnifying glass as the enter key)
If we focus the input when the menu opens: $("#menu_search").focus() - The search keyboard is open when the menu displays and we are able to search BUT as soon as we tap in the input the keyboard changes to a regular keyboard and we a not able to type anything.
Another clue is that while typing in the keyboard the auto-predict works but when tapping on the correct option only a space is added to the input and none of the other characters.
We have tried a bunch of other attribues on the search input to no avail:
<input type="search" placeholder="Search..." name="search" id="menu_search" value="" data-role="none" autocomplete="off" autocorrect="off" autocapitalization="off" role="textbox" aria-autocomplete="list" aria-haspopup="true" style="-webkit-appearance:searchfield;" class="ui-autocomplete-input" />
This all works fine on a HTC Desire running 2.2 and a desire running CM7 (Android 2.3.7)
We even tried changing the input to a textarea but this did pretty much the same thing :(
I also tried:
$("#menu_search").live('focus',function(event){
event.preventDefault();
});
to see if that would prevent it from changing keyboards but no luck either.
We do however have another search input elsewhere in the app which works fine, the only difference being that the other search is in a "propper" page: data-role="page" and the menu is outside of all of the other pages and in its own just set to hidden initially.
Please help, im crying blood atm!
You probably have
-webkit-user-select: none;
In your CSS somewhere. If you enable text selection for inputs
input, textarea { -webkit-user-select: text; }
it works again!
Did you try adding data-native-menu="false" attribute to your search input tag.
If you're still stuck on this, try updating to phonegap 2.0. It fixes some input problems.
$('#pageid').live('pageshow', function(event, ui) {
$(this).delegate('input[data-type="search"]', 'keyup', function () {
if($(this).val().length != 0)
keyword = $(this).val();
});
});
i'v create an app using phonegap + jequery you look for it in playStore "AssignmentReminder" or type in the search field koshWTF.
anyway. i'd encouraged this issue before and haven't fixed it as i guess its 4.0.1 issue not the phone gap nor jquery mobile , because i still can type under 4.0.4 and lesser. hope you find the answer for it because i did search aloot last time and couldn't find it.
I have/had the same issue on my Note II running 4.1.1 rooted using Phonegap 2.6.0 (though I can also replicate it in 2.5.0), jQuery Mobile 1.2.0, and jQuery 1.7.2. My keyboard is SwiftKey 4.0.1.128.
Except rather than just one input causing me issues, my form has multiple inputs that eventually cause me trouble. It's a real headache because it's hard to replicate - the input always works at first, but if you switch between inputs randomly and long enough, it eventually stops working at a random time.
This error used to happen fairly quickly, so that it would make it a pretty significant issue considering I would have to restart the app to get the form working again, which would eventually stop working yet again. My new form structure seems to work well; the error occurs after literally minutes of typing long strings and randomly switching inputs, which I assume no user will be doing; but it still upsets me that the error is there.
I tried to get help on this error on the jQuery Mobile forum, but they gave me some snarky comment about how it's likely just my element ID usage, because apparently 99% (probably not even realistic) of JQM errors are from incorrect ID usage. I know for a fact my IDs are all unique across every page, but they insist it's an ID error without even trying to correctly diagnose the issue, but I digress.
I should also note that I found the CSS solution that was provided in another answer in many other similar issues across the web, but not this exact issue; while I understand its usage, the CSS did not fix the issue for me.
My form is dynamically loaded into a data-role="content" DIV inside of a data-role="page" DIV, so:
<div data-role="page">
<div data-role="content" id="my-form-holder">
</div>
</div>
I've found the best form structure, at least in my application, to cause the error least frequently is:
<form id="account-add" action="add-edit-account.php" method="post" data-ajax="false" autocomplete="off">
<div data-role="fieldcontain" class="ui-hide-label">
<label for="custom-name">
</label>
<input name="custom-name" placeholder="Account Name" value="Service Name Here" type="text"><br>
<label for="custom-1">
</label>
<input name="custom-1" placeholder="User ID" type="text"><br>
<label for="custom-2">
</label>
<input name="custom-2" placeholder="Password" type="password"><br>
<input type="hidden" name="action" value="add-2">
<input type="hidden" name="newserviceid" value="3">
<input type="hidden" name="userid" value="1">
<input id="account-add-submit" type="submit" name="account-add-submit" value="Add Account">
</div>
</form>
The form HTML is fetched via AJAX and loaded into the DIV by:
$(ajaxData).appendTo("#my-form-holder").trigger("create");
Naturally, your form will be a bit different, and you may not even have a form since you just have a search input (getting to that in a moment). But if you do have a form, that's what works best for me.
Since you're in Phonegap, you may not even need an action theoretically since you likely have jQuery to handle the input, but jQuery Mobile docs state forms must have action and method attributes, so I didn't want to go against that. Also, jQuery Mobile usually has a data-role="field-contain" DIV around each label/input group, but I found that the error occurred sooner if I did this. Again, the error occurs at an arbitrary moment that is never the same, so I don't know if it's directly related to the DIV.
I also have an input hard-coded into another page:
<div data-role="fieldcontain" class="ui-hide-label">
<label for="service-search-input">
</label>
<input name="service-search-input" id="service-search-input" placeholder="Enter a service to search for" type="search">
</div>
This seems to work fine. However, there are no other inputs to switch to, so the best I can do to try to replicate the error is focus/unfocus the input by tapping elsewhere on the page. Though, I am always able to type initially whereas your error doesn't let you type at all if I understand correctly. You may want to try that HTML structure and see if it works. There is no form tag surrounding that input.
Our issues are a little different (I have most of my issues with a dynamically injected form whereas yours is hard-coded from what I gather), but this is the only page I could find anywhere that directly addresses this exact issue, so hopefully this helps and we can get some further insight on this issue.

Categories

Resources