I'm doing an small class to load spreadsheets and insert data in them but when I insert a row i retrieve an error:
Expected response code 200, got 400 We're sorry, a server error
occurred. Please wait a bit and try reloading your spreadsheet.
I have looking in this site and google and some people has this error when they trying to insert data with capital letters or spaces... i'm not trying to insert data like this so i suppose that this is not my error. I the code that is giving me problems:
try {
echo $this->_spreadId . '<br>';
echo $this->_defaultWorksheetId . '<br>';
echo get_class($this->_spreadClient) . '<br>';
$rowData = array('stuff' => 'smurf');
$this->_spreadClient->insertRow($rowData, $this->_spreadId, $this->_defaultWorksheetId);
} catch (Exception $exc) {
echo '<br><pre>' . $exc->getTraceAsString() . '</pre>';
echo '<br>' . $exc->getMessage();
}
The output of this script is:
tVe4Mr82qD3LRhubQrcLxMQ
od6
Zend_Gdata_Spreadsheets
#0 /home/sergi/projects/quiniela2gdocs/lib/Zend/Gdata.php(219): Zend_Gdata_App->performHttpRequest('POST', 'https://spreads...', Array, 'performHttpRequest('POST', 'https://spreads...', Array, 'post('insertEntry('insertRow(Array, 'tVe4Mr82qD3LRhu...', 'od6')
Expected response code 200, got 400 We're sorry, a server error occurred. Please wait a bit and try reloading your spreadsheet.
Another method of this class is creating the spreadsheet and it's doing well, so i think there aren't connecting issues with gDocs.
Some help is welcome.
Lots of thanks !!
I had a similar problem which has arisen due to the presence of spaces in the array. Remove spaces helped me:
$rowData = array('stuff' => 'smurf'); - your code
$rowData = array('stuff'=>'smurf'); - my code
Related
I am using PHRETS Library to fetch the rets feed. At the time of image fetching its providing me the ErrorCode "20401". Object to fetch image from rets api as:
$objects = $rets->GetObject('Property', 'CmmlRntl', '75290', '*', 0);
foreach ($objects as $photo) {
$photo = $photo->getContent();
if($photo){
echo "<hr><pre>";
var_dump($photo);
//echo "<img src=\"data:image/jpeg;base64," . base64_encode('') . "\" />";
echo "</pre><hr>";
}
}
Output Getting As:
string '<RETS ReplyCode="20401" ReplyText="Requested Type not found." />' (length=64)
How i can get rid from this Error.?
I had the same issue, and couldn't find an answer to that problem, even after asking the MLS IT dept.
What I ended up doing was to have a cron that re-tries to fetch those images which I flag as 'failed', but the retry will is limited to 2 retries. If, after that, the image is still failing, then the retry script won't try to fetch it again.
For the most part, the error happened due to a failure on the MLS server, and usually I was able to fetch the image on the 2nd try.
Does anybody know why
$this-response($somearray, 200);
Can't output a long JSON? (Or long arrays)
For example I can output DB result if I limit query to last 10 rows but if I limit it to 100
JSON gets trimed and in my client app I get 'unexpected end of input'. If I change above statement in simple
echo json_encode($somearray);
It works flawlessly.
I am sorry. I need to clarify my question. I am using
https://github.com/chriskacerguis/codeigniter-restserver
function transits_get()
{
$sessionId = $this->input->get_request_header('Sessionid', TRUE);
$transits = $this->Transit_model->get_transits( $sessionId );
if($transits)
{
//$this->output->set_content_type('application/json');
//$this->output->set_output(json_encode($transits)); //works
//echo json_encode($transits); //works
$this->response($transits, 200); // 200 being the HTTP response code //Does not work
}
else
{
$this->response(array('error' => 'There is no transit records in the database!'), 404);
}
}
Alright, I've found what was the problem.
I simply commented out the code in REST_controller that sets content length.
Now it works but I am still wondering why strlen($output) is not as same length as output JSON for larger JSON files and it is ok for short ones.
// If zlib.output_compression is enabled it will compress the output,
// but it will not modify the content-length header to compensate for
// the reduction, causing the browser to hang waiting for more data.
// We'll just skip content-length in those cases.
if ( ! $this->_zlib_oc && ! $this->config->item('compress_output')) {
//header('Content-Length: ' . strlen($output));
}
This works for me, and I have lots of JSON data (+- 250 records):
$this->output->set_content_type('application/json');
$this->output->set_output(json_encode($data));
As found in this article, you can do the following:
Open REST_Controller.php
Locate and delete the following code (at the end of the response function):
if ( ! $this->_zlib_oc && ! $CFG->item('compress_output')) {
header('Content-Length: ' . strlen($output));
}
In libraries folder, line no. 267 of REST_Controller.php file, comment the following code. it's working.
header('Content-Length: ' . strlen($output));
For months I've been running the "Box Rest Client" lib by Angela R that employs the following code to parse curl responses from the box API:
$xml = simplexml_load_string($res);
Today, after the code loops through dozens of request/responses I generate this following error:
ErrorException [ Warning ]: simplexml_load_string(): Entity: line 9:
parser error : Comment not terminated
This happened in 2 straight attempts to run the code - and now seems to have gone away without any changes to anything.
Interested if anyone knows what is up with that?
I have put a catch for this case if its useful to anyone using this lib (for the next month or so before its deprecated by box api 2.0)
private function parse_result($res) {
try {
$xml = simplexml_load_string($res);
$json = json_encode($xml);
$array = json_decode($json,TRUE);
return $array;
} catch (Exception $e){
$error = 'xml parsing error: '. $e->getMessage(). "<br>";
return array('status' => $error );
}
}
It's possible it is related to including two minus signs -- inside of an HTML comment. For example:
<!-- this is my comment--but not a very good one. -->
The two dashes in the middle of the comment causes problems with the parser.
Hopefully the solution to this is a lot more simple than what I've been trying!
I've got a Symfony 2.3 app where I'm attempting to get the number of followers of a Twitter users account. I get back data but I can't access it by array key/index values.
Controller Action:
public function twitterAction(){
$twitterClient = $this->container->get('guzzle.twitter.client');
$response = $twitterClient->get('1.1/followers/ids.json?screen_name=ACCOUNTNAME')
->send()->json();
return $this->render('CatablogSiteBundle:Default:status.html.php', array('response' => $response));
}
View:
<?php
var_dump($response);
echo '<br><br>';
echo gettype($response);
echo '<br><br>';
echo $response[0];
?>
I get back data that I want to use from var_dump, gettype responds with type Array , and attempting to reference $response[0] will fail completely.
What can I do to access data inside the response Object?
edit:
Of course I can't echo $response[0] ... (wrong type) don't try and code tired guys. Solved whilst going over NHG's answer, which is still helpful for anyone having problems with Guzzle.
If I understood TwitterClient extends Guzzle\Service\Client (based on https://github.com/RobinvdVleuten/guzzle-clients/blob/master/Twitter/TwitterClient.php, isn't it?). So, let's try this one:
echo $response->getBody();
// for getting body
echo $response->getHeader('Content-Length');
// for getting Content-Length body
$data = $response->json();
// for getting response in json format
Docs: http://guzzlephp.org/tour/http.html#using-a-client-object
This is my first question :).
Im writing a little twitter app in PHP that sends a DMs to all your followers. What im trying to do right now is to get the list of followers. So through twitter api and getting all usernames but for some reason this parsing error appear. Im new to php(but not so much to programming), I actually started learning it yesterday so please be easy on me ;).
Here is the code:
$t= new twitter();
$t->username= $_GET["username"];
$t->password= $_GET["password"];
$fi = $t->followers();
$xml[$page] = new SimpleXMLElement($fi[2]);
$user1count=0;
while(isset($xml[$page]->user[0])){
foreach ($xml[$page]->user as $user) {
$userdet[(string)$user->screen_name]=array( ’screen_name’=> (string)$user->screen_name, ‘location’=>(string)$user->location, ‘description’=>(string)$user-> description, ‘profile_image_url’=> (string)$user-> profile_image_url, ‘url’=>(string)$user-> url, ‘name’=>(string)$user->name );
$user1details[$user1count]= (string)$user->screen_name;
$user1count++;
}
$page++;
$fi=getfilecontents($friendsurl.$username1."xml?page".$page);
if($fi[0]===false){
echo ("Error :".$fi[1]);
$err=new SimpleXMLElement($fi[2]);
echo " ".$err->error." ";
// echo ““;
die();
}
$xml[$page] = new SimpleXMLElement($fi[2]);
}
And the error said:
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /Applications/XAMPP/xamppfiles/htdocs/scripts/dmsend.php:125 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/scripts/dmsend.php(125): SimpleXMLElement->__construct('') #1 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/scripts/dmsend.php on line 125
Thank you! :)
It looks like $fi[2] is not a valid xml string. I am not 100% familiar with the twitter API, but I would do a var_dump($fi) and evaluate what is begin returned. From there, you should be able to figure out what is happening.