1
votes

I'm trying out http requests to download a pdf file from google docs using google document list API and OAuth 1.0. I'm not using any external api for oauth or google docs.

Following the documentation, I obtained download URL for the pdf which works fine when placed in a browser.

According to documentation I should send a request that looks like this:

GET https://doc-04-20-docs.googleusercontent.com/docs/secure/m7an0emtau/WJm12345/YzI2Y2ExYWVm?h=16655626&e=download&gd=true  

However, the download URL has something funny going on with the paremeters, it looks like this:

https://doc-00-00-docs.googleusercontent.com/docs/securesc/5ud8e...tMzQ?h=15287211447292764666&amp\;e=download&amp\;gd=true    

(in the url '&amp\;' is actually without '\' but I put it here in the post to avoid escaping it as '&').

So what is the case here; do I have 3 parameters h,e,gd or do I have one parameter h with value 15287211447292764666&ae=download&gd=true, or maybe I have the following 3 param-value pairs: h = 15287211447292764666, amp;e = download, amp;gd = true (which I think is the case and it seems like a bug)?

In order to form a proper http request I need to know exectly what are the parameters names and values, however the download URL I have is confusing. Moreover, if the params names are h,amp;e and amp;gd, is the request containing those params valid for obtaining file content (if not it seems like a bug).

I didn't have problems downloading and uploading documents (msword docs) and my scope for downloading a file is correct.

I experimented with different requests a lot. When I treat the 3 parameters (h,e,gd) separetaly I get Unauthorized 401. If I assume that I have only one parameter - h with value 15287211447292764666&ae=download&gd=true I get 500 Internal Server Error (google api states: 'An unexpected error has occurred in the API.','If the problem persists, please post in the forum.').

If I don't put any paremeters at all or I put 3 parameters -h,amp;e,amp;gd, I get 302 Found. I tried following the redirections sending more requests but I still couldn't get the actual pdf content. I also experimented in OAuth Playground and it seems it's not working as it's supposed to neither. Sending get request in OAuth with the download URL responds with 302 Found instead of responding with the PDF content.

What is going on here? How can I obtain the pdf content in a response? Please help.

1
How did you receive the download URL? It may have been HTML entity encoded. - John Watts
I've been sending and browsing responses using OAuth Playground and an online tool for sending requests - hurl and they both responded with &amp instead of & in the response body. However when I used another online tool - api kitchen the URL was correct - no amps, so you must be right here, thanks a lot:) However I already tried sending request for obtaining the file with params e,gd,h and I'm getting 401 unatuthorized - user1453389
On the second thought, I'm still unsure about http entity encoding, I assumed OAuth Playground and hurl encoded the actual response and api kitchen didn't, however placing the url with &amps in the browser works - it opens the pdf and if I use the url from api kitchen - with & instead of &amps I get nothing in the browser, so maybe entity encoding is on google side and api kitchen did decoding, I'm confused here - user1453389
Never mind the previous comment - what's interesing if I put download URL in the browser while being logged to gmail (no authorization needed) and I use 3 parameteres h,e,gd nothing happens, if I don't put all of the 3 params in the URL, the pdf content shows up in the browser, so obviously nothing special about having 3 params - h, &amph, &ampgd - user1453389

1 Answers

0
votes

I have experimented same issue with oAuth2 (error 401).

Solved by inserting the oAuth2 token in request header and not in URL.

I have replaced &access_token=<token> in the URL by setRequestHeader("Authorization", "Bearer <token>" )