UrlFetchApp.fetch( ) url with | - url

I have a url I want to get using google scripts' UrlFetchApp.fetch( ) command. Unfortunately this url has a | (gets partially encoded into %7c) in it and every time i try to fetch it I get an error saying 'invalid argument'. Any idea how to get around this issue and successfully fetch the url?

It seems to work if the url passed to UrlFetchApp.fetch is already encoded.
Let's say you want to fetch www.google.com/aaa|bbb (which doesn't really exist). The following script fails with "invalid argument":
UrlFetchApp.fetch("www.google.com/aaa|bbb");
But this one correctly returns a 404 as the request is valid but the page is not found:
UrlFetchApp.fetch("www.google.com/aaa%7Cbbb");
If that doesn't help, it would help if you could paste your url.

Related

Syntax error at position 57 in 'TimeZoneStandard='microsoft.graph.timeZoneStandard'Iana'''

I'm trying to request the supported timezones in the IANA format for a user (in Java), and getting the following error:
Error code: RequestBroker--ParseUri
Error message: Syntax error at position 57 in 'TimeZoneStandard='microsoft.graph.timeZoneStandard'Iana'''.
GET https://graph.microsoft.com/v1.0/users/email#redacted.com/outlook/microsoft.graph.supportedTimeZones(TimeZoneStandard=microsoft.graph.timeZoneStandard'Iana')
SdkVersion : graph-java/v2.3.1
Authorization : [PII_REDACTED]
400 : Bad Request
[...]
Based on our test suit, the request was working fine 3 days ago, and started failing with that error yesterday. We haven't changed anything for a while on our implementation, so I'm a bit baffled. For the request I'm essentially doing the following:
final String url = requestBuilder.outlook()
.getRequestUrlWithAdditionalSegment("microsoft.graph.supportedTimeZones(TimeZoneStandard=microsoft.graph.timeZoneStandard'Iana')");
final OutlookUserSupportedTimeZonesCollectionRequestBuilder builder = new OutlookUserSupportedTimeZonesCollectionRequestBuilder(
url, requestBuilder.getClient(), null
);
IOutlookUserSupportedTimeZonesCollectionPage page = builder.buildRequest().get();
The reason I'm doing this instead of the standard:
final IOutlookUserSupportedTimeZonesCollectionPage page = requestBuilder.outlook()
.supportedTimeZones(TimeZoneStandard.IANA)
.buildRequest()
.get();
Is because this isn't working as expected, as described here: https://github.com/microsoftgraph/microsoft-graph-docs/issues/7594 (the issue is for C#, but happens in Java too).
What I notice is that the GET url looks fine, and works fine in the Graph Explorer using the /me endpoint instead of the /users endpoint. But the string in the error message looks modified:
'TimeZoneStandard='microsoft.graph.timeZoneStandard'Iana'''
If I'm not mistaken, the outer apostrophes are simply quoting done when printing the error message, but there are further apostrophes introduced after the = sign, which aren't present in the GET URI, which might be causing the syntax error. Still, I have no idea where those come from.
Any help or hint would be greatly appreciated!
I have modified the call something like this
https://graph.microsoft.com/v1.0/users/UPN/outlook/supportedTimeZones(TimeZoneStandard='Iana')
It worked for me.

What format of url is this with the colon almost in the end - https://speech.googleapis.com/v1p1beta1/speech:longrunningrecognize

I am trying to consume the google text to speech api here : https://cloud.google.com/speech-to-text/docs/async-recognize#speech-async-recognize-gcs-protocol
and it has this url format below
https://google-speech-api-base-urlspeech:longrunningrecognize
What is this URL format with colon(:)in the end?
When I try to hit this URL, it gives me an error specifically while running test case on it .e. Invalid URI. Invalid Port?
But the official google documentation says this is a valid url? How to use this?
This format of URL is called gRPC Transcoding syntax. Your first URL is invlaid , because it's in the first path segment of a relative-path reference.
https://google-speech-api-base-urlspeech:longrunningrecognize
This url is invalid for usage, whereas the one below, https://speech.googleapis.com/v1/speech:longrunningrecognize was running fine.
Try changing your URL to something like
https://google-speech-api-base-url/speech:longrunningrecognize. It will work.
I looked at the documentation page you referenced and was unable to see/find a URL that looked like:
https://google-speech-api-base-urlspeech:longrunningrecognize
However, what I did find was a URL of the form:
https://speech.googleapis.com/v1/speech:longrunningrecognize
which looks perfectly valid.
The documentation for this REST request can be found here:
https://cloud.google.com/speech-to-text/docs/reference/rest/v1/speech/longrunningrecognize
Could you have made an error in your reading and comprehension?
Apparently the colon (:) is legal in the path part of a URL:
Are colons allowed in URLs?

ERROR STATUS: URL contains outer http

I have a COLDFUSION page which except parameters from url and show them in fields. My url looks like this which is working.
http://www.example.com/test.cfm?activeUrl=www.msn.com&secure=False
But following is not working. I have added http before www in activeUrl value.
http://www.example.com/test.cfm?activeUrl=httpwww.msn.com&secure=False
It is giving me following error. "ERRROR STATUS: URL contains outer http"
Can any one help me to solve this problem?
For me, It seems that something related to iis configuration.
The string in httpwww.msn.com is causing your browser error. It should be http://www.msn.com, but should also be URL encoded.
ohh, i have not checked the application.cfc ONREQUESTSTART method. it has some condition for query string, which is showing this error. :(

Large number of likes but now realise it is to an invalid url

My site at www.kruaklaibaan.com (yes I know it's hideous) currently has 3.7 million likes but while working to build a proper site that doesn't use some flowery phpBB monstrosity I noticed that all those likes are registered against an invalid URL that doesn't actually link back to my site's URL at all. Instead the likes have all been registered against a URL-encoded version:
www.kruaklaibaan.com%2Fviewtopic.php%3Ff%3D42%26t%3D370
This is obviously incorrect. Since I already have so many likes I was hoping to either get those likes updated to the correct URL or get them to just point to the base url of www.kruaklaibaan.com
The correct url they SHOULD have been registered against is (not url-encoded):
www.kruaklaibaan.com/viewtopic.php?f=42&t=370
Is there someone at Facebook I can discuss this with? 3.7m likes is a little too many to start over with without a lot of heartache. It took 2 years to build those up.
Short of getting someone at Facebook to update the URL, the only option within your control that I could think of that would work is to create a custom 404 error page. I have tested such a page with your URL and the following works.
First you need to set the Apache directive for ErrorDocument (or equivalent in another server).
ErrorDocument 404 /path/to/404.php
This will cause any 404 pages to hit the script, which in turn will do the necessary check and redirect if appropriate.
I tested the following script and it works perfectly.
<?php
if ( $_SERVER['REQUEST_URI'] == '/%2Fviewtopic.php%3Ff%3D42%26t%3D370' ) {
Header("HTTP/1.1 301 Moved Permanently");
Header("Location: /viewtopic.php?f=42&t=370");
exit();
} else {
header('HTTP/1.0 404 Not Found');
}
?><html><body>
<h1>HTTP 404 Not Found</h1>
<?php echo $_SERVER['REQUEST_URI']; ?>
</body></html>
This is a semi-dirty way of achieving this, however I tried several variations in Apache2.2 using mod_alias's Redirect and mod_rewrite's RewriteRule, neither of which I have been able to get working with a URL containing percent encoded chars. I suspect that with nginx you may have better success at a more graceful way to handle this in the server.

Google docs API: can't download a file, downloading documents works

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.
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>" )

Resources