admin管理员组文章数量:1124691
I'm working on a Google Apps Script project and facing an issue with the openByUrl method from the DocumentApp class.
Here's the problem: I'm using the following document URL:
When I try to open the document using DocumentApp.openByUrl, I get this error:
Unexpected error while getting the method or property openByUrl on object DocumentApp.
Below is the code snippet:
var url = ";;
var doc = DocumentApp.openByUrl(url);
I've verified the following:
The URL is correct and accessible.
The document is shared with the script.
Does anyone have an idea of what could be wrong? Is there a better approach to opening a document using a URL?
Thank you!
I'm working on a Google Apps Script project and facing an issue with the openByUrl method from the DocumentApp class.
Here's the problem: I'm using the following document URL: https://docs.google.com/document/d/1bmad4K86Ov1zQHiu8gbX6GpOSL9kbNGKiE3jmaJN9N8/edit?usp=drive_web
When I try to open the document using DocumentApp.openByUrl, I get this error:
Unexpected error while getting the method or property openByUrl on object DocumentApp.
Below is the code snippet:
var url = "https://docs.google.com/document/d/1bmad4K86Ov1zQHiu8gbX6GpOSL9kbNGKiE3jmaJN9N8/edit?usp=drive_web";
var doc = DocumentApp.openByUrl(url);
I've verified the following:
The URL is correct and accessible.
The document is shared with the script.
Does anyone have an idea of what could be wrong? Is there a better approach to opening a document using a URL?
Thank you!
Share Improve this question asked 2 days ago Vikram AruchamyVikram Aruchamy 1822 silver badges12 bronze badges 2- 1 I found a very similar post in Reddit reddit.com/r/GoogleAppsScript/comments/1hxc2z8/… also posted two hours ago. – Wicket Commented 2 days ago
- 1 Please add a minimal reproducible example – Wicket Commented 2 days ago
1 Answer
Reset to default 0Does anyone have an idea of what could be wrong? Is there a better approach to opening a document using a URL?
Based on my research, there are some similar cases to yours, however, their issue involves incorrect document ID
as it is not following the 44 character format, which does not work with your case.
As per the method itself, I don't think that there is an issue with your current approach, it should work as intended, unless there's more to your code that you still haven't provided through your question, or a possible bug.
I would suggest using the openById()
method instead as each document has a unique ID, which does not change even with altering the location of the document within the Google drive, therefore, you would not experience the disadvantage of changing the URL each time.
You can try this approach:
function myFunction() {
var url = "1bmad4K86Ov1zQHiu8gbX6GpOSL9kbNGKiE3jmaJN9N8";
var doc = DocumentApp.openById(url);
}
If this is not suitable for your needs, kindly provide more information and show us your complete code. It might be due to different parts of it. Also provide the Oauth scopes you have within your script, It can be the reason why it does not acknowledge the method you are using.
Reference: openById(), openByUrl()
本文标签: google docsApps Script DocumentAppopenByUrl Unexpected ErrorStack Overflow
版权声明:本文标题:google docs - Apps Script: DocumentApp.openByUrl Unexpected Error - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736644059a1946064.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论