我正在尝试向 url https://www.googleapis.com/groups/v1/groups/ "+group_id 发送一个获取请求,其中组 id 是一个唯一的组 id,我希望得到一个描述设置的响应一个小组,但我得到了回应
{ "error": { "errors": [ { "domain": "global", "reason": "authError", "message": "Domain cannot use Api, Groups service is not installed.", "locationType": "header", "location": "Authorization" } ], "code": 401, "message": "Domain cannot use Api, Groups service is not installed." } }
我在我的项目 api 中启用了我的组设置 api,并且我的域中的组服务已打开,谁能告诉我为什么会收到此错误以及如何摆脱此错误?我正在使用 google 应用程序进行商业版免费试用. 这是我在java中发送get请求的java代码
package org.ritesh;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Group_Detail extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse resp){
resp.setContentType("text/HTML");
String access_token=req.getParameter("access_token");
String group_id=req.getParameter("group");
String url="https://www.googleapis.com/groups/v1/groups/"+group_id+"?alt=json";
URL ur;
try {
ur = new URL(url);
HttpURLConnection conn=(HttpURLConnection) ur.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("GET");
conn.setRequestProperty("Authorization", "OAuth "+access_token);
InputStream str= conn.getInputStream();
BufferedReader reader=new BufferedReader(new InputStreamReader(str));
String l="";
resp.getWriter().println("<html><head>Group Detail</head><body>");
while((l=reader.readLine())!=null)
{resp.getWriter().println(l);
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
我在请求参数中获得了 access_token 和 groupid ,它们肯定是正确的。