create empty spreadsheet in google docs - php

i want to create a empty spreadsheet with google docs api but i get the error: could not convert document.
$xml = "--END_OF_PART\r\n".
"Content-Type: application/atom+xml;\r\n\r\n".
"<?xml version='1.0' encoding='UTF-8'?>
<entry xmlns=\"http://www.w3.org/2005/Atom\" xmlns:docs=\"http://schemas.google.com/docs/2007\">
<category scheme=\"http://schemas.google.com/g/2005#kind\"
term=\"http://schemas.google.com/docs/2007#spreadsheet\"/>
<title>".$name."</title>
</entry>\r\n".
"--END_OF_PART\r\n".
"Content-Type: text/csv;\r\n\r\n".
"--END_OF_PART--\r\n";
This xml is sent to the server of google with a post with param convert=true
Then i got the error: could not convert document.
When i use the mime-type 'application/vnd.oasis.opendocument.spreadsheet' instead of 'text/csv' and do not add the param convert=true i get an internal error.

Docs List API v3 is deprecated. Use Google Drive API instead. You can create a file with the insert call:
https://developers.google.com/drive/v2/reference/files/insert
the mimeType for a native spreadsheet would be:
application/vnd.google-apps.spreadsheet

Related

How to convert youtube api data to xml data feed using php?

I have an idea to convert this JSON data:
https://www.googleapis.com/youtube/v3/videos?part=snippet&chart=mostPopular&maxResults=50&regionCode=us&videoCategoryId=10&key=Mykey
to xml ,To use for feeds Rss reader
How to do this using PHP only ?
My respect
Youtube API only returns JSON. You can load the json in your code and implement your own XML using
header('Content-type: text/xml');
// other headers are required
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
echo '<xml>';
// Your data
echo '</xml>';

Copy images in Google Drive to own server using PHP

I have a folder in Google Drive with product images (the folder is public). On request I want these images to be uploaded to my website.
Is there a simple way to copy all images to my own server using PHP, whitout having to set my mind into Google Drive API?
This gives me nothing to work with:
<?php
$url = "https-link-to-the-public-folder";
$html= file_get_contents($url);
print_r($html);
?>
The most straightforward method for uploading a file is by making a simple upload request. This option is a good choice when:
The file is small enough to upload again in its entirety if the connection fails.
There is no metadata to send. This might be true if you plan to send metadata for this resource in a separate request, or if no metadata is supported or available.
To use simple upload, make a POST or PUT request to the method's /upload URI and add the query parameter uploadType=media. For example:
POST https://www.googleapis.com/upload/drive/v3/files?uploadType=media
The HTTP headers to use when making a simple upload request include:
Content-Type. Set to one of the method's accepted upload media data types, specified in the API reference.
Content-Length. Set to the number of bytes you are uploading. Not required if you are using chunked transfer encoding.
The following example shows the use of a simple upload request for the Drive API.
POST /upload/drive/v3/files?uploadType=media HTTP/1.1
Host: www.googleapis.com
Content-Type: image/jpeg
Content-Length: number_of_bytes_in_file
Authorization: Bearer your_auth_token
JPEG data

MSXML2.DOMDocument Object required error if file extension is not .xml

Working on an application to retreive shipping rates as XML from a web service. The web service is PHP based. The client is VB Script, specifically HTA.
During initial development I used an XML file on the server as a test. Here is the content of that file:
<shipping>
<rate>
<method>FEDEX GROUND</method>
<description>FedEx Ground</description>
<amount>10.00</amount>
</rate>
<rate>
<method>FEDEX 2 DAY</method>
<description>FedEx 2nd Day</description>
<amount>20.00</amount>
</rate>
<rate>
<method>FEDEX NEXT DAY</method>
<description>FedEx Next Day</description>
<amount>30.00</amount>
</rate>
</shipping>
When I use MSXML2.ServerXMLHTTP to get that file I have no issues using MSXML2.DOMDocument to parse the XML.
If I attempt to get the exact same XML from a PHP script, or even if I copy the XML file to a filename with a non-xml extension, like .txt, I get an Object Required error trying to access the document elements.
When getting the data from PHP I am setting the header like so:
header('Content-Type: application/xml; charset=utf-8');
Here is the VB Script code:
Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "GET", "http://craig.clearos.lan/c9pets/api/shippingRates", False
xmlhttp.send
results=xmlhttp.ResponseText
Set xmlDoc = CreateObject("MSXML2.DOMDocument")
xmlDoc.load(xmlhttp.responseXML)
Set ratesNodeCollection = xmlDoc.DocumentElement.getElementsByTagName("rate")
This errors out on the last line with "Object required: 'xmlDoc.DocumentElement'"
If I change line 2 to this
'xmlhttp.open "GET", "http://craig.clearos.lan/sage/hello.xml", False
it works as expected.
Again, I have verified that the PHP code and the .txt file contain the exact same XML as the .xml file.
I have added parseError trapping and I'm getting the message "XML document must have a top level element." This makes no sense to me. There is a top level element named I've also added to the .xml file and the output of PHP. This did not change anything. I tried setting the header to text/xml instead of application/xml, which also did nothing.
For reference here is the very simple php code that builds the XML.
$shipping=array(0=>array('method'=>'FEDEX GROUND', 'description'=>'FedEx Ground', 'amount'=>'10.00'),
1=>array('method'=>'FEDEX 2 DAY', 'description'=>'FedEx 2nd Day', 'amount'=>'20.00'),
2=>array('method'=>'FEDEX NEXT DAY', 'description'=>'FedEx Next Day', 'amount'=>'30.00'));
$xml=new SimpleXMLElement('<shipping/>');
foreach($shipping as $row){
$rate=$xml->addChild('rate');
$rate->addChild('method', $row['method']);
$rate->addChild('description', $row['description']);
$rate->addChild('amount', $row['amount']);
}
Header('Content-type: application/xml');
print($retVal->asXML());

How to post with specific content type in Zend?

Is there a way to POST a specific Content-type using Zend GData? Specifically I want to post a file with type
"Content-Type: application/vnd.youtube.timedtext; charset=UTF-8"
Otherwise, will I need to use cURL?
Thanks!
You can set the specific content type of your file with setContentType() with something like this:
$yt = new Zend_Gdata_YouTube($httpClient);
$filesource = $yt->newMediaFileSource('your_file.ext');
// content type you want to use
$filesource->setContentType('application/vnd.youtube.timedtext; charset=UTF-8');
There is good example with more options at Zend Framework: Documentation: Using the YouTube Data API - Zend Framework Manual : Uploading Videos to YouTube.

php rest webservice

how can i get a xml file when i pass a parameterized url
If you are generating the XML file in PHP, try setting the header as the first line of the script.
header("Content-type: text/xml");

Categories