Java 错误400谷歌应用程序组设置api中的无效值
我正在尝试使用put请求调用一个url,该url为 但是 将错误响应获取为{“error”:{“errors”:[{“domain”: “全局”、“原因”:“必需”、“消息”:“必需”}],“代码”: 400,“消息”:“必需”} 如果我打开链接 然后有一个TryIt部分,我用OAuth2.0授权它,并放置一些字段,如图所示 我编写了一个Javaservlet来调用这个url 这是它的doGet方法代码,我正在Google Appengine上编写。我用oauth2授权了应用程序,并且acess_令牌有效,否则它将显示授权错误。 它显示了无效的值Java 错误400谷歌应用程序组设置api中的无效值,java,google-app-engine,google-api,httprequest,gdata,Java,Google App Engine,Google Api,Httprequest,Gdata,我正在尝试使用put请求调用一个url,该url为 但是 将错误响应获取为{“error”:{“errors”:[{“domain”: “全局”、“原因”:“必需”、“消息”:“必需”}],“代码”: 400,“消息”:“必需”} 如果我打开链接 然后有一个TryIt部分,我用OAuth2.0授权它,并放置一些字段,如图所示 我编写了一个Javaservlet来调用这个url 这是它的doGet方法代码,我正在Google Appengine上编写。我用oauth2授权了应用程序,并且acess
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
String url = "https://accounts.google.com/o/oauth2/token";
// FetchOptions opt = FetchOptions.Builder.doNotValidateCertificate();
URL url1=new URL(url);
String param="code="+req.getParameter("code")+"&client_id=719226850877-tr21kp47phthuli0hu2v24akgfrplde9.apps.googleusercontent.com&client_secret=hSXi3dWfEmDQfl0XZJJmBssc&redirect_uri=https://www.onemoredemo.appspot.com/oauth2callback&grant_type=authorization_code";
HttpURLConnection connection =
(HttpURLConnection)url1.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
connection.getOutputStream().write( param.getBytes() );
InputStream str= connection.getInputStream();
BufferedReader reader=new BufferedReader(new InputStreamReader(str));
String l="";
String l1="";
while((l=reader.readLine())!=null){
l1+=l;
resp.getWriter().println(l);
}
try {
JSONObject obj=new JSONObject();
obj.put("email", "testing9@iritesh.com");
JSONObject json=new JSONObject(l1);
String access_token=json.getString("access_token");
URL url2=new URL("https://www.googleapis.com/groups/v1/groups/testing@iritesh.com?key=AIzaSyATDZHO5J7a3ItTSBhPby__Xzxi7rZlMJQ");
HttpURLConnection connection1=(HttpURLConnection) url2.openConnection();
connection1.setRequestMethod("PUT");
connection1.addRequestProperty("Content-Type", "application/json");
connection1.setDoOutput(true);
connection1.addRequestProperty("Authorization","Bearer "+ access_token);
connection1.getOutputStream().write(obj.toString().getBytes());
connection1.connect();
InputStream str1= connection1.getInputStream();
BufferedReader reader1=new BufferedReader(new InputStreamReader(str1));
String rit;
while( (rit=reader1.readLine())!=null)
{resp.getWriter().println(rit);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
我试图提出与图中相同的请求。
首先将key参数设置为api key,然后通过调用setRequestMethod(“PUT”)将请求方法设置为PUT;
之后增加了两个属性,一个是授权:承载访问令牌
然后是内容类型:application/json
然后通过调用方法将其请求体设置为json对象
connection1.getOutputStream().write(obj.toString().getBytes());
有人能告诉我哪里错了,我在哪里输入了无效值吗?因为我正在尝试更改组的电子邮件地址,但当我在组页面中手动尝试时,它无法更改,这就是为什么我收到400个错误的原因。如果您稍微更改一下标题,可能会得到更好的响应