从Chrome扩展程序向Google执行API发送请求时出现404错误

时间:2016-05-01 15:28:27

标签: javascript google-chrome-extension google-apps-script execution-api

当我从Chrome扩展程序发出google执行api请求时,我收到404错误。

我确定我的客户端ID正确且范围正确。 另外,我要调用的脚本ID和函数名也是正确的。

我还将脚本作为api可执行文件发布给每个人。

以下是我的示例chrome扩展文件。

请给我一个帮助!

我长期坚持这个问题。

的manifest.json

<%@page import="java.io.*"%>
<%@page import="java.util.*"%>
<%@page import="org.apache.commons.*" %>
<%@page import="net.sf.json.JSONObject"%>
<%@page import="net.sf.json.JSONSerializer"%>

<%@page import="org.apache.commons.httpclient.HttpClient"%>
<%@page import="org.apache.commons.httpclient.methods.PostMethod;"%> 

<%

String sp_clientid="64557e87-806e-41bb-9760-acc42de3f281";
String sp_clientsecret="4c115ba5-58d8-44d0-9378-0abe9d1bb9f8";
String sp_refreshtoken="40b19430-5d83-42f6-8b27-14c9cf70b8c1";

String GRANT_TYPE = "refresh_token";
String PARAM_GRANT_TYPE = "refresh_token";

String url="https://api0.silverpop.com/oauth/token";
HttpClient httpclient = new HttpClient();
String responseText="";

PostMethod post = new PostMethod(url);
post.setParameter("client_id",sp_clientid);
post.setParameter("client_secret", sp_clientsecret);
post.setParameter("refresh_token", sp_refreshtoken);
post.setParameter("grant_type",PARAM_GRANT_TYPE);

httpclient.executeMethod(post);
//responseText=getResponseText(post);
InputStream is = post.getResponseBodyAsStream();
Scanner scanner = new Scanner(is).useDelimiter("\\A");
responseText=scanner.hasNext() ? scanner.next() : "";

System.out.println(responseText);

%>



<html>
<head>

<link rel="stylesheet" type="text/css" href="default.css" media="screen" />     
</head>

<body>
        HELLO WORLD
        <TABLE BORDER="0" cellpadding="0" CELLSPACING="0" class=boldtable>
        <TR>
        <FONT size="15">
        <TD WIDTH="450" HEIGHT="600">

        </TD>


        </TR>
        </TABLE>
        </FONT>



</body>

</html>

background.js

{
  "name": "Execution Api Test",
  "version": "0.1",
  "manifest_version": 2,

  "description": "Execution Api Test",

  "permissions": [
    "identity",
    "tabs",
    "http://*/*",
    "https://*/*"
  ],

  "background": {
    "scripts": ["background.js"]
  },

  "oauth2": {

    "client_id": "816912884742-icjd8pjj58m4rvrh211f1rrg97bkepho.apps.googleusercontent.com",

    "scopes": [
      "https://www.googleapis.com/auth/spreadsheets"
    ]

  },

  "page_action": {
    "default_icon": "icon.png",
    "default_title": "test"
  }


}

#我需要的所有信息!!!

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

Google Execution API存在问题。目前,您无法使用Exection API的服务帐户。有跟踪票: https://code.google.com/p/google-apps-script-issues/issues/detail?id=5461 它包含可能的解决方法。 您也可以在GScript中使用它来正确授权: https://github.com/googlesamples/apps-script-oauth2