I've recently integrated Google Drive's API into a website that I'm building on CodeIgniter. The website is all about writing an essay and converting that into Word document that I've managed to upload into Google Drive using the API script provided
However, I'm not able to preview or open the uploaded document right on Google Drive. But, I'm able to view and edit it once I download the Document from Google drive and open via Microsoft Word processor
please advise what I should be doing to make my document editable on Google drive using Google doc's tool.
here is the coding that I used to upload the document generated from the website and here is the sample document attached.
Please Note: Like I aforementioned, when I re-upload the document that I download from Google drive back to Google drive then the document works fine and I'm able to preview as well as edit it.
if ($_SERVER['REQUEST_METHOD'] == 'POST' && $client->getAccessToken()) {
// We'll setup an empty 1MB file to upload.
$doc_file = $this->session->userdata('google_doc_file');
DEFINE("TESTFILE", __DIR__ . '/../../../papers/'.$doc_file.'.docx');
// This is uploading a file directly, with no metadata associated.
$file = new Google_Service_Drive_DriveFile();
$file->setName($doc_file.'.docx');
$result = $service->files->create(
$file,
array(
'data' => file_get_contents(TESTFILE),
'mimeType' => 'text/docx',
'uploadType' => 'multipart'
)
);
}
Related
I download a Google Doc file in Json format (application/vnd.google-apps.document) from Google using documents.get.
How do I upload this file back to Google Drive? The description for documents.create method clearly says that it can create only a blank document:
Creates a blank document using the title given in the request. Other
fields in the request, including any provided content, are ignored.
Are there any other method to upload application/vnd.google-apps.document (in native Google format, not docx)?
Note that unlike documents.create, spreadsheets.create method allows uploading file content and works just fine.
I have google api service account.I successfully upload the file on the drive, open the file on browser.But i am not able to get the edit mode.How can i open a particular file in edit mode.And the changes will reflect to original files.
Currently i open the file using link "https://drive.google.com/file/d/0B6TZcMlVILILeEN2al9KanZBS1k/view?usp=drivesdk" this does not support the edit mode. When the current user sign in on the above link page then i see the edit option but it saves to the current user logged in account and not reflect the original file.
You can try the above link its working now.
I am developing the application in asp.net MVC and using google api v2
One approach is to share the files to the users (depending on type in your use case). Once the file has been uploaded (thru Service Account), additional settings will be required to share the file. Set the role as writer and you'll be good to go (by calling the File's selfLink)
I prefer iOS (Objective-C) code but the question is linked with google drive API. So a solution in any other programming language may belong here.
My previous code:
GTLQueryDrive *query = [GTLQueryDrive queryForFilesList];
query.q = ...;
... //send query and get links to files
But it was correct in Google Drive API v2 only - query returned a list of GTLDriveFile objects and GTLDriveFile contained field downloadUrl.
But Google Drive API v3 doesn't have such field and according to this document I should perform additional request with queryForFilesGetWithFileId: and link 2 results between themselves, shouldn't I? How to solve this issue?
downloadUrl has been removed. If you want download file, i have tried successfully!
How to download pdf from google drive V3 API in IOS?
Referring to Download Files, you'll use one of the given URLs below, depending on the type of download that you'd like to perform.
Download a file — files.get with alt=media file resource
Download and export a Google Doc — files.export
Link a user to a file — webContentLink from the file resource
For example, to download a file using alt=media, you make an authorized HTTP GET request to the file's resource URL and include the query parameter alt=media. Using the sample request format:
GET https://www.googleapis.com/drive/v3/files/0B9jNhSvVjoIVM3dKcGRKRmVIOVU?alt=media
Authorization: Bearer ya29.AHESVbXTUv5mHMo3RYfmS1YJonjzzdTOFZwvyOAUVhrs
As stated, your app must be authorized with a scope that allows reading of file content. And, an app using the drive.readonly.metadata scope would not be authorized to download the file contents. Users with edit permission may restrict downloading by read-only users by setting the viewersCanCopyContent field to true.
Please check through the documentation for the detailed instructions for performing the given types of downloads.
I am developing a net console application for downloading adwords reports.
It is work perfectly fine for facebook reports.
But when I am doing the same with GDN, Google AdWords' csv file is downloaded in HTM format with no actual data.
My Ruby code is:
link='link url in scheduled report'
GDN_Form = page.forms[0]
GDN_Form.Email ='LOGIN ID'
GDN_Form.Passwd = 'PASSWORD'
puts "Redirecting to Page"
#puts page.to_html
#Subitting the login Page
GDN_Form.add_field! 'send','Submit'
page = agent.submit(GDN_Form, GDN_Form.buttons[0])
agent.get(link)
page2 = agent.get(link)
puts page2.title
agent.get(link).save('C:\Ruby21\DownloadedeReports\ClientName.CSV')
The file is downloaded, but actual data is not downloaded.
I have to to do this task without using Google APIs.
Google login procedure has changed, first you need to find login url which it comes with _ga cookie id which is dynamically changed.
Here is the e.g.
https://accounts.google.com/ServiceLogin?service=adwords&continue=https://adwords.google.com/um/identity?sourceid=awo&subid=in-ww-di-awhp&hl=en_IN&_ga=1.229603486.307864125.1437111208&hl=en_IN<mpl=signin&passive=0&skipvpage=true#identifier
and login page contains email id which you have to find using mechanize then click on the next, same you have to do with password. After submit click on your schedule report url.
I'm having some seriously weird issues with the Google Drive API.
Bear with me here, there's a lot to explain.
I originally got the API working using one of my Google accounts -- let's call it test#google.com for simplicity. I got the Google Picker UI working and it correctly displays the list of files in my Drive account.
I set it to my APP_ID and I have some server-side logic that uses the official google-ruby-api-client gem to connect to the Drive API using the drive.files.get endpoint. I can then download the file's metadata using this snippet:
require 'google/api_client'
client = Google::APIClient.new
# client ID and secret from Google APIs Console
client.authorization.client_id = "{CLIENT_ID}"
client.authorization.client_secret = "{SECRET}"
client.authorization.redirect_uri = "http://myapp.com/users/auth/gdrive"
# access token stored in database from oauth2 flow
client.authorization.access_token = "TOKEN"
client.authorization.scope = [
"https://www.googleapis.com/auth/drive.file",
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/userinfo.profile"
]
result = client.execute!(
:api_method => 'drive.files.get',
:version => 'v2',
:parameters => { 'fileId' => params[:file_id] })
With the test#google.com account I tried this on, the result comes back with the file's metadata, and I'm able to download the file. All peachy.
The problem comes when I use a different Google account. I can access the files in Picker, but when the request is sent to the server with the fileId using the above, I just keep getting a 404 error, saying that the file doesn't exist. I've also tried to access the file's metadata using the OAuth 2.0 Playground provided by google, but the weird thing is that I still get that error, but I also get the same 404 error when I use the test#google.com account.
The only thing I can really think of is that I submitted a version of my app with all the Google Drive details once, and installed the app via the Chrome Webstore. After I realized it was showing up for everyone as a Drive-enabled app, I promptly removed it and changed the manifest.json file back to its normal, non-Drive enabled state. I did read that you should have the app installed via the Chrome Webstore to work properly, but I also read that that's not the case anymore. Are your installed Chrome Webstore apps stored in Google's cloud somewhere so they know that it was installed for a particular account? Or are webstore apps just installed locally? I'm so confused.
What am I missing here? I haven't been this frustrated with an API in a really long time. Please help!
Thanks to Ali Afshar for the answer -- the solution (for now) is to temporarily use the full scope of Google Drive instead of just the drive.file scope.
e.g. instead of using this scope,
https://www.googleapis.com/auth/drive.file
use this one instead:
https://www.googleapis.com/auth/drive