微信公众平台“发生未知错误”的解决方法之一

最近想玩微信公众平台开发。
在填写服务器配置的时候,点击提交总也不通过,显示“发生未知错误,请重试”(大意如此);
搜了半天也没得到什么有用的东西,有很多答案居然是换个浏览器就可以了。然而我从Chrome到Firefox到Edge甚至IE都换过了,依然没有解决。

随后读了一下文档,猜想,该不是在提交配置的时候微信公众平台就要测试吧?
就快速写了一个客户端。按照文档方法加密验证签名。果然提交成功。

关键点在下面:

开发者提交信息后,微信服务器将发送GET请求到填写的服务器地址URL上,GET请求携带参数如下表所示:

参数
描述
signature 微信加密签名,signature结合了开发者填写的token参数和请求中的timestamp参数、nonce参数。
timestamp 时间戳
nonce 随机数
echostr 随机字符串

开发者通过检验signature对请求进行校验(下面有校验方式)。若确认此次GET请求来自微信服务器,请原样返回echostr参数内容,则接入生效,成为开发者成功,否则接入失败。加密/校验流程如下:

1)将token、timestamp、nonce三个参数进行字典序排序

2)将三个参数字符串拼接成一个字符串进行sha1加密

3)开发者获得加密后的字符串可与signature对比,标识该请求来源于微信

简单来说就是验证一下服务器。在提交服务器设置的时候你可以不用管这个验证过程,直接返回echostr即可。等配置提交完成了再实现也没问题。

 

所以微信你可否给一些更友好一点的错误提示呢?诸如“未能连接到你的服务器”?

WebExtension: Block request after response header received in Firefox and Chrome Extension

Well. Firefox finally admitted that Chrome’s extension system is better than it’s XUL or Add-on SDK.

So from Firefox 45+, it started to support WebExtension. And now, it even does not allow any extension that is not built with WebExtension API.

This is a good news, because if you want your extension run on both Chrome and Firefox. you won’t need to build twice.

However, even Firefox is trying to support all of the WebExtension API. There are still some differences between Chrome and Firefox.

Recently I got this one.

I was trying to block some requests with the WebRequest API after response header just received. In Chrome, you can easily do it with an onHeadersReceived listener. like this:

 chrome.webRequest.onHeadersReceived.addListener(
    function (details) {
        let block = THE CONDITIONS THAT YOU WANT TO USE;
        return {cancel: block};

    },
    {urls: ["URL PATTERN"], types: ["TYPES"]},
    ["blocking"]); 

But in Firefox, this is not gonna work. Because in Firefox, you can not block a request after the response headers received, you can only redirect it. So you need to to this:

 chrome.webRequest.onHeadersReceived.addListener(
    function (details) {
        let block = THE CONDITIONS THAT YOU WANT TO USE;
        return {cancel: block, redirectUrl: "://127.0.0.1"};

    },
    {urls: ["URL PATTERN"], types: ["TYPES"]},
    ["blocking"]); 

with the redirectUrl: “://127.0.0.1”, you will redirect it to a local address, and means block it.

How to fix “[Error] ScriptError: Document DocumetID is missing (perhaps it was deleted?)” in Google Script

I’ve created a Google Script APP to help someone export Gmail data to Google SpreadSheet.

It works well when I was testing. But after I publish it as web app, and other users got an error which says

[Error] ScriptError: Document DOCUMENT_ID is missing (perhaps it was deleted?).

And no authorize permission form popups up.  I did not get any useful answer in Google.

After several tests I found I made a stupid mistake.

When publishing the Google Script as web app or other types of APP. There are several options need to take carefully.

Execute the app as:

should set as “User accessing the web app“. (The default value is  Me(myself email)).

With this option, when user first use your app, the authorize permission form will popup and ask user to allow your app access their Google APP.

And no more Document is missing error.

Also don’t forget to chose Anyone in the Who has access to the app option.

 

 

 

How to debug Chrome extension Native Messaging app

 

Here is how to debug native messageing: enable logging.

By adding a flag, it can open Chrome logging window when starting Chrome.

For Windows, you just need to right click on the Chrome icon in your installation folder / shortcut / taskbar —— Properties  —— add this line behind the target string:

[code]–enable-logging –v=1[/code]

A logging window will start with the Chrome. There the native messaging stuff will be print out.

Firefox: How to install and use addon that is not from AMO

In former version, users can install Firefox addon easily by drag and drop the addon file (.xpi file)  into Firefox to install and use it.

But now, user can not do this by default. User can only install addon from AMO (https://addon.mozilla.org). If you download an addon from other website or like me develop addon self. when you drag and drop the file into Firefox. it will be disabled and can not be enable. It says : ADDON NAME could not be verified for use in Firefox and has been disabled.  like this(I’m using Nightly Firefox):

Unnamed QQ Screenshot20151104000045

well, it’s easy to pass this by these steps.

1: Navigate to about:config in Firefox (input about:config into Firefox’s address bar and hit Enter)

2: You might see a warning screen warning the action is not safe. Just hit the blue button  I’ll be careful, I promise .

3:You will see a long list. Input the keywords xpinstall  in the search bar.

4: Find the xpinstall.signatures.required, it’s value should be true now. click this line, change the value to false.

xpinstall

5: You are done, you will see that your addon enabled and working:)

 

Google will shut down Google Code

Well, Google said, there are more great services like Github and Bitbucket, so Google code is not needed any more,  it will shut down Google code service soon. And there is some tools to export your projects to other platform like Github, Bitbucket or SourceForge.

The shut down schedule is:

  • March 12, 2015 – New project creation disabled.
  • August 24, 2015 – The site goes read-only. You can still checkout/view project source, issues, and wikis.
  • January 25, 2016 – The project hosting service is closed. You will be able to download a tarball of project source, issues, and wikis. These tarballs will be available throughout the rest of 2016.

At the same time, Google says it will continue serve some projects like Android and Chrome so that user can continue git them. And also will continue maintaining  mirrors for projects like Eclipse kenel.

Google also gives an export tool to export your project to Github.  And also here is another tool to export any of your projects to Github/Bitbucket/SourceForge.

SourceForge also supplies an import tool to import Google code project.

 

Firefox Addon: How to use gmail.js in Firefox Addon SDK

Well, gmail.js is a very nice script that if you want to work with Gmail (developing browser extensions for Gmail).

The author says that gmail.js is designed for Chrome extension development. There is also many examples about how to use it in Chrome extension. But, how to use it in Firefox addon development?

If you inject it directly in the page, you will got an error: GLOBAL is not defined.

it is because the gmail.js uses 2 variables in the Gmail page, GLOBAL  and also VIEW_DATA. If you inject it directly by pageMode, it can not access any page script.

So you need to modify the gmail.js, in line 6 and 7 (if line number is different, just search it ). By using unsafeWindow , you can access the Gmail page variable:
change

api.tracker.globals =GLOBALS;

to
api.tracker.globals = unsafeWindow.GLOBALS;

change

api.tracker.view_data = typeof VIEW_DATA !== "undefined" ? VIEW_DATA : [];

to

api.tracker.view_data = typeof unsafeWindow.VIEW_DATA !== "undefined" ? unsafeWindow.VIEW_DATA : [];

Then you can use the gmail.js without error.

Actually in Chrome extension, you can not inject gmail.js with content script decoration in manifest.json directly, because in that way  you can not access GLOBAL too.

You need to use another content script to inject it  with add <script> block in the page, here  is the code snap

window.onload = function () {

    //inject jQuery
    var jq = document.createElement('script');
    jq.src = chrome.extension.getURL("lib/jquery-2.1.1.min.js");
    document.body.appendChild(jq)

    //inject gmail.js
    var sm = document.createElement('script');
    sm.src = chrome.extension.getURL("lib/gmail.js");
    document.body.appendChild(sm);
    //inject the script that actual do your things 
    var ct = document.createElement('script');
    ct.src = chrome.extension.getURL("content.js");
    document.body.appendChild(ct);
}

Then declare this file as content script in the manifest.json. and also declare all 3 scripts in web_accessible_resources.

终于调通了Google API For JavaScript

说起来惭愧,作为一名Google开发者,这么重要一个API 应该很早以前就会用的。但是因为其他工作一直忙,这个目标就没有实现…

这两天趁着周末时间,研究了两天,终于学会了怎么调用Google的一系列API。

这意味着,我能针对Google产品做更多事情了。

为自己欢呼一下。

Chrome: How to use extension that not from web store

From  version 35,  Chrome will disable extensions that not come from Chrome web store. It do makes your Chrome safer,  But it also bring some problems for some users.  That is, If you are using a extension that you don’t want to upload it to the Chrome web store, you can not use it anymore. This extension will be disabled and can not be enabled:

Well, here is how to re-enable extensions like this (not from Chrome Web Store):

  1. navigate to chrome://extensions page. delete the disabled extension by clicking the trash icon
  2. find your extension file that ends with .crx or .zip extension.
  3. right click on the file, use 7-zip software(or any other extract tool) with “Extract to…” command to extract the extension
  4. drag and drop the extracted FOLDER to the chrome://extensions page.
  5. Confirm the permissions  confirmation information
  6. You are done.

Here is how to do it :

http://screencast.com/t/Ma3KnTIw

You can also manage your extensions with my Extension
One Click Extension Manager -No Ads