无法使 Gmail 上下文小工具工作 - 2015 API 版本
Cannot make Gmail contextual gadget work - 2015 API version
我目前正在为一家非营利组织开发 Gmail 上下文小工具。
我们遵循 https://developers.google.com/gmail/contextual_gadgets 上的官方 Google 教程,目标是构建 Hello World 应用程序。
我们做了以下工作:
- 在 https://console.developers.google.com/
上创建应用
- 激活Google Marketplace SDK
- 使用适当的提取器和小工具 URL 激活 GMail 上下文小工具。
- 为非营利组织用户部署应用程序。
- 向我们发送包含 "Hello World".
的电子邮件
但是,我们无法让它工作(它应该在电子邮件下方打印 Hello World)。我们检查了托管 XM 的服务器,Google 肯定命中了我们的 gadget_helloworld.xml 文件。
文件内容如下。有人可以帮忙解决这个问题吗?
很难找到关于此主题的最新文档,因为 Google API 改变了很多东西。我认为提供一个在 2015 年最后更新的开源工作代码示例会对社区有所帮助。
最佳,
提取器的内容 - manifest_helloworld.xml
<?xml version="1.0" encoding="UTF-8"?>
<ApplicationManifest xmlns="http://schemas.google.com/ApplicationManifest/2009">
<script id="tinyhippos-injected" />
<Extension id="HelloWorldExtractor" type="contextExtractor">
<Name>Hello World Extractor</Name>
<Url>google.com:HelloWorld</Url>
<Triggers ref="HelloWorld" />
<Scope ref="emailBody" />
<Scope ref="emailSubject" />
<Container name="mail" />
</Extension>
<Extension id="HelloWorld" type="gadget">
<Name>HelloWorld Gadget</Name>
<Url>XXXX_MY_DOMAIN/gadget_files/gadget_helloworld.xml</Url>
<Container name="mail" />
<!-- Uncomment this to enable Caja. -->
<!-- Param name="caja" value="enabled"/> -->
</Extension>
<Scope id="emailBody">
<Url>tag:google.com,2010:auth/contextual/extractor/BODY</Url>
<Reason>Necessary for reason 1</Reason>
</Scope>
<Scope id="emailSubject">
<Url>tag:google.com,2010:auth/contextual/extractor/SUBJECT</Url>
<Reason>Necessary for reason 2</Reason>
</Scope>
</ApplicationManifest>
小工具的内容 - gadget_helloworld.xml
<?xml version="1.0" encoding="UTF-8"?>
<Module>
<script id="tinyhippos-injected" />
<ModulePrefs title="Hello World" description="Matches and echoes 'Hello World' string in emails" height="20" author="ACME" author_email="test@example.com" author_location="Bermuda">
<!-- Declare feature dependencies. -->
<!--
This one is not specific to Gmail contextual gadgets.
-->
<Require feature="dynamic-height" />
<!--
The next feature, Caja, is optional, and is supported for
use only within test domains. Uncomment the tag only for
non-production gadgets.
-->
<!-- <Require feature="caja"/> -->
<!--
The next feature, google.contentmatch, is required for all
Gmail contextual gadgets.
<Param> - specify one or more comma-separated extractor IDs in
a param named "extractors". This line is overridden by the extractor ID
in the manifest, but is still expected to be present.
-->
<Require feature="google.contentmatch">
<Param name="extractors">google.com:HelloWorld</Param>
</Require>
</ModulePrefs>
<!--
Define the content type and display location. The settings
"html" and "card" are required for all Gmail contextual gadgets.
-->
<Content type="html" view="card"><![CDATA[<p>Hello World</p>
<script type="text/javascript">
<!-- Fetch the array of content matches. -->
matches = google.contentmatch.getContentMatches();
var matchList = document.createElement('UL');
var listItem;
var extractedText;
<!-- Iterate through the array and display output for each match. -->
for (var match in matches) {
for (var key in matches[match]) {
listItem = document.createElement('LI');
extractedText = document.createTextNode(key + ": " + matches[match][key]);
listItem.appendChild(extractedText);
matchList.appendChild(listItem);
}
}
document.body.appendChild(matchList);
gadgets.window.adjustHeight(100);
</script>]]></Content>
</Module>
我有一个类似的问题,它没有激活,我的解决方案是将 "Extractor param name" 设置为 "hello" 并将 "Extractor param value" 设置为“.*” - - According to the docs 重要的部分是值域:
If you really do want your gadget to be triggered by all possible
values in the extractor's default output, explicitly set the regular
expression as value=".*". This makes it clear that you have cast a
wide net by design.
我目前正在为一家非营利组织开发 Gmail 上下文小工具。 我们遵循 https://developers.google.com/gmail/contextual_gadgets 上的官方 Google 教程,目标是构建 Hello World 应用程序。
我们做了以下工作:
- 在 https://console.developers.google.com/ 上创建应用
- 激活Google Marketplace SDK
- 使用适当的提取器和小工具 URL 激活 GMail 上下文小工具。
- 为非营利组织用户部署应用程序。
- 向我们发送包含 "Hello World". 的电子邮件
但是,我们无法让它工作(它应该在电子邮件下方打印 Hello World)。我们检查了托管 XM 的服务器,Google 肯定命中了我们的 gadget_helloworld.xml 文件。
文件内容如下。有人可以帮忙解决这个问题吗?
很难找到关于此主题的最新文档,因为 Google API 改变了很多东西。我认为提供一个在 2015 年最后更新的开源工作代码示例会对社区有所帮助。
最佳,
提取器的内容 - manifest_helloworld.xml
<?xml version="1.0" encoding="UTF-8"?>
<ApplicationManifest xmlns="http://schemas.google.com/ApplicationManifest/2009">
<script id="tinyhippos-injected" />
<Extension id="HelloWorldExtractor" type="contextExtractor">
<Name>Hello World Extractor</Name>
<Url>google.com:HelloWorld</Url>
<Triggers ref="HelloWorld" />
<Scope ref="emailBody" />
<Scope ref="emailSubject" />
<Container name="mail" />
</Extension>
<Extension id="HelloWorld" type="gadget">
<Name>HelloWorld Gadget</Name>
<Url>XXXX_MY_DOMAIN/gadget_files/gadget_helloworld.xml</Url>
<Container name="mail" />
<!-- Uncomment this to enable Caja. -->
<!-- Param name="caja" value="enabled"/> -->
</Extension>
<Scope id="emailBody">
<Url>tag:google.com,2010:auth/contextual/extractor/BODY</Url>
<Reason>Necessary for reason 1</Reason>
</Scope>
<Scope id="emailSubject">
<Url>tag:google.com,2010:auth/contextual/extractor/SUBJECT</Url>
<Reason>Necessary for reason 2</Reason>
</Scope>
</ApplicationManifest>
小工具的内容 - gadget_helloworld.xml
<?xml version="1.0" encoding="UTF-8"?>
<Module>
<script id="tinyhippos-injected" />
<ModulePrefs title="Hello World" description="Matches and echoes 'Hello World' string in emails" height="20" author="ACME" author_email="test@example.com" author_location="Bermuda">
<!-- Declare feature dependencies. -->
<!--
This one is not specific to Gmail contextual gadgets.
-->
<Require feature="dynamic-height" />
<!--
The next feature, Caja, is optional, and is supported for
use only within test domains. Uncomment the tag only for
non-production gadgets.
-->
<!-- <Require feature="caja"/> -->
<!--
The next feature, google.contentmatch, is required for all
Gmail contextual gadgets.
<Param> - specify one or more comma-separated extractor IDs in
a param named "extractors". This line is overridden by the extractor ID
in the manifest, but is still expected to be present.
-->
<Require feature="google.contentmatch">
<Param name="extractors">google.com:HelloWorld</Param>
</Require>
</ModulePrefs>
<!--
Define the content type and display location. The settings
"html" and "card" are required for all Gmail contextual gadgets.
-->
<Content type="html" view="card"><![CDATA[<p>Hello World</p>
<script type="text/javascript">
<!-- Fetch the array of content matches. -->
matches = google.contentmatch.getContentMatches();
var matchList = document.createElement('UL');
var listItem;
var extractedText;
<!-- Iterate through the array and display output for each match. -->
for (var match in matches) {
for (var key in matches[match]) {
listItem = document.createElement('LI');
extractedText = document.createTextNode(key + ": " + matches[match][key]);
listItem.appendChild(extractedText);
matchList.appendChild(listItem);
}
}
document.body.appendChild(matchList);
gadgets.window.adjustHeight(100);
</script>]]></Content>
</Module>
我有一个类似的问题,它没有激活,我的解决方案是将 "Extractor param name" 设置为 "hello" 并将 "Extractor param value" 设置为“.*” - - According to the docs 重要的部分是值域:
If you really do want your gadget to be triggered by all possible values in the extractor's default output, explicitly set the regular expression as value=".*". This makes it clear that you have cast a wide net by design.