Downloading Gdoc revisions from Google Drive API v3 - java

You can't I know. From the docs,
Once you get a list of a file's revisions, you can download the content of any revision by calling the revisions.get method with the parameter alt=media. Revisions for Google Docs, Sheets, and Slides can not be downloaded.
But I'd like to download(pdf) different versions of the same Gdoc file based on date. From the Drive web app you can view versions and print them or restore a version to the head. Is there any way to achieve either using the API? Can you restore some version ? Then you could export the file.
I searched the internets, but couldn't find a way around this.
I'm using the java client api, which gives me this when I try to make a media get request.
{
"code" : 403,
"errors" : [ {
"domain" : "global",
"location" : "alt",
"locationType" : "parameter",
"message" : "Only files with binary content can be downloaded. Use Export with Google Docs files.",
"reason" : "fileNotDownloadable"
} ],
"message" : "Only files with binary content can be downloaded. Use Export with Google Docs files."
}
But I can figure it out if you can answer for any other API too.

Looks like a v3 specific issue. I suggest using v2 for that particular call. See https://developers.google.com/drive/v2/reference/revisions#resource , where you will see that the revision resource contains an array called exportLinks. Within that you should find an element {"pdf":"https://xxxxxxxx"}. Make an authenticated GET on that URL.
imho, the provided libraries cause as many problems as they solve. This is a case in point where the library masks access to the v2 API, even though the v2 API is fully supported. So in your code, you will need to extract the Access Token from the drive service object, set that as an http Authorization: Bearer 4a343234we43w43w44 header, then make the two GET REST calls to GET the revisions list and then GET the url corresponding to pdf in the exportLinks.

Related

Office365 API get content of ReferenceAttachment

I'm trying to process attachments that were added to my event and I have difficulties in loading the attachments that has the following type:
"#odata.type": "#Microsoft.OutlookServices.ReferenceAttachment"
The problem is that for usual attachments:
"#odata.type": "#Microsoft.OutlookServices.FileAttachment"
Office365 sends ContentBytes in the response with the complete content of the file. In case with the ReferenceAttachment there is no ContentBytes field in the response.
I didn't find anything useful about ReferenceAttachment in the doc:
https://msdn.microsoft.com/en-us/office/office365/api/calendar-rest-operations#get-attachments .
However, I did succeed in finding some info in the documentation for beta version.
https://msdn.microsoft.com/en-us/office/office365/api/complex-types-for-mail-contacts-calendar#referenceattachment-preview
There should be SourceUrl, but I don't have it in my response either.
I really appreciate your help in finding a way to get the content of such attachments. Thanks!
I've found the solution. The reason why I wasn't able to get a source URL was the fact that this works only for beta version. I look forward to having it in a stable version, however, I will use beta one by that time.
So, to make it working, we need to change version in the path parameter to beta.
e.g.
https://outlook.office.com/api/beta/me/events/{eventId}/attachments/
Instead of:
https://outlook.office.com/api/v2.0/me/events/{eventId}/attachments/
Having done that, you will be able to see the following in your response:
"SourceUrl": "https://.../guestaccess.aspx?docid=...",
One more interesting poiunt here. If it's an Office document and you want to directly download it instead of just openning it at online editor, you can change guestaccess to download. Thus you will be able to download.

Business Objects Login failed while using SDK

I am migrating a BI3.X API application to BI4.1. The purpose of the application is to retrieve PDF reports from SAP BOE.
I have referred few documents and was able to make it using Opendoc URL. But I only receive HTML as response in opendoc URL. So I decided to go with SDK to retrieve PDF as response..
I am facing problem while logging on to the application using SDK. The BOE cluster name is accessible from web browser but I am not able to ping it.
Earlier I was getting token for the opendoc using secLDAP authentication with below URL
http://server.domain.com:6405/biprws/logon/long
The code I am using now:
ISessionMgr sessionMgr = CrystalEnterprise.getSessionMgr();
IEnterpriseSession enterpriseSession =
sessionMgr.logon("username", "password", "server.domain.com:6405", "secEnterprise");
String sessionToken = enterpriseSession.getLogonTokenMgr().getDefaultToken();
While running above code I get the following error message.
Not able to connect CMS. Specify the correct host and port and check for network issues.
I tried to see the problem.
http://server.domain.com/BOE/BI is accessible
but when I try to ping server.domain.com, it is not reachable.
Any idea what should I do now ? I am still not sure how this works as I am new to SAP environment.
I am not even sure if I should use the same server name which I used with opendoc.
You can specify the outformat with opendocument URL. Just add the parameter sOutputFormat. Possible values are:
H: HTML
P : PDF
E : Excel (Crystal Reports only)
W : RTF (Crystal Reports only)
So you will have the following URL:
http://server:port/BOE/OpenDocument/opendoc/openDocument.jsp?iDocID=AZuIwjRPI2BApS7VCZMFpNs&sIDType=CUID&sOutputFormat=P
You can also use the docId if you don't have the cuid
http://server:port/BOE/OpenDocument/opendoc/openDocument.jsp?iDocID=5676&sOutputFormat=P
OpenDocument URL documentation is available here: https://help.sap.com/businessobject/product_guides/sbo41/en/sbo41_opendocument_en.pdf
For exporting rep file in PDF format with the REST API, you have to use the following URI:
http:///infostore//rpt/export?mime_type=application/pdf
Crystal Reports RESTful documentation is available here: http://help.sap.com/businessobject/product_guides/sbo41/en/sbo41sp3_cr_restws_en.pdf

Wrong MIME Type on JasperReports Server response?

We have a JasperReports Server (5.5.0 community edition) running our reports and consuming them through REST services API from our web application.
When we ask a report output through reports execution API we get the proper output and we are able to download it correctly, BUT, the problem is that the downloaded file is downloaded without an extension and therefore the final user can't open it propperly (it has to rename it or choose the proper program to open it). This is caused for several reasons according to what we were able to figure out:
First, the generated output on Jasper server has no name set up, here is an example:
{
"status": "ready",
"totalPages": 1,
"currentPage": null,
"errorDescriptor": null,
"requestId": "338384569_1404312281871_3",
"reportURI": "/uri_to_report",
"exports": [
{
"status": "ready",
"errorDescriptor": null,
"outputResource": {
"contentType": "application/xls",
"fileName": null
},
"id": "xls"
}
]
}
As we can see, the "fileName" property is null, and hence when we ask the output with
<JASPER_SERVER_URL/jasperserver/rest_v2/reportExecutions/338384569_1404312281871_3/exports/xls/outputResource>
we get a file called "outputResource" with no extension. This causes that download attribute on links element useless, we have tried this option. And we weren't able to figure out a way to set up this file name in Jasper server internally.
The other reason is that the MIME type of the response is not set properly for some output formats (we tried with XLS, XLSX and DOCX formats). As we can see, is set to "application/xls" for XLS output when should be "application/vnd.ms-excel" according to IANA or even MICROSOFT and the browser is not able to set up a default file name with the proper extension. For this, we have implemented a Servlet Filter in embedded Tomcat, but it seems that the response is flushed before we can set up the proper Content-Type header to it.
We are going to report this possible bug to Jasper community but since we wait an answer we keep searching for workarounds to this problem, so, any suggestions?
Thanks in advance to all of you.

Getting Google plus profile image

I have been developing a Java language application.
Now i am trying to show the logged in user photograph as part of the user data, but i dont seem to get it right.
Through UserService i am getting the user id, and with the user id and my application api key, i am trying to build the image url to load it into my application.
But it isnt working.
The url i am building is : https://www.googleapis.com/plus/v1/people/{USER_ID}?fields=image&key={API_KEY}
But i keep getting the same error :
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "accessNotConfigured",
"message": "Access Not Configured. Please use Google Developers Console to activate the API for your project."
}
],
"code": 403,
"message": "Access Not Configured. Please use Google Developers Console to activate the API for your project."
}
}
I have enabled as well the following API in Google Developers Console:
Drive API
Drive SDK
Google Cloud SQL
Google Compute Engine
Google Picker API
Google+ API
Can anyone lend me a hand on this?. Sorry if i waste your time with something obvious.
Check that you're using the right value for the API key. They're under Public API access in the Credentials section of the developer console and should look like something like this: AIzaSyC2WWuM97gdij5k5uRduLFeL3LuURBvFpo - make sure it's of that form, and associated with the project you have enabled the API for.

TaskQueueSample.java : Code 403

I am trying to make the sample works so here is the code :
Sample Code
The documentation for the installation is there:
Installation documentation
I had a little problem on the step:
Click on "API Access", and then on "Create an OAuth 2.0 Client
ID...". Enter a product name and click "Next".
The UI of the console has been upgraded probably so I use those data for the authentication in the console:
Then I run the program and it brings me to the webpage to allow the app and then i got the following error message in the console:
403 Forbidden
{
"code" : 403,
"errors" : [ {
"message" : "you are not allowed to make this api call"
} ],
"message" : "you are not allowed to make this api call"
}
My queue.xml ACL is set with the email i used to authenticate
Why don't you use the native TaskQueue-API from the GAE Java SDK? You don't need to set up credentials, connection, ... .
You can see an example on the GAE Docs - here a Pull Queue, but you can also use a Push Queue if you want (an example is also in the GAE Docs).
Which one of the examples do you want to launch on the google app engine? On your posted link are many examples available :) . Tell me if you really want to use the Google-API to access the TaskQueues.

Categories