2012-07-19 67 views
0

我试图打电话与PUT请求一个URL,URL是错误400无效值Apps群组设置API

PUT https://www.googleapis.com/groups/v1/groups/groupUniqueId但作为{“错误” 收到错误响应:{“错误” :[{“domain”: “global”,“reason”:“required”,“message”:“Required”}],“code”: 400,“message”:“Required”}}

如果我打开链接 https://developers.google.com/google-apps/groups-settings/v1/reference/groups/update 然后有一个Try It Section i auth与OAuth2.0的orize它,并把一些领域如图像enter image description here

我写一个Java servlet调用此URL 这里是它的doGet方法的代码,我写它在谷歌Appengine.i授权广告应用程式使用的oauth2并且acess_token是有效的,否则它将显示授权错误。 它显示我无效的值。

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", "[email protected]"); 
      JSONObject json=new JSONObject(l1); 
      String access_token=json.getString("access_token"); 
      URL url2=new URL("https://www.googleapis.com/groups/v1/groups/[email protected]?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(); 
     } 


    } 

我试图做出一个请求在图像相同。 首先将关键参数设置为api键,然后通过调用setRequestMethod(“PUT”)将请求方法设置为PUT; 之后加入的两种性质的一种是授权:承载的access_token 然后内容类型:应用/ JSON 然后通过调用方法

connection1.getOutputStream().write(obj.toString().getBytes()); 

设置其请求体作为JSON对象任何一个可以请点我在哪里我错了,我在哪里放无效价值?

+2

如果更改书名有点可能会得到更好的反应 – dfb 2012-07-19 03:03:38

+0

[SSCCE](http://robzu.com/sscce-short-self-contained-correct-compilable-example/) – RobB 2012-07-19 03:10:44

+0

更改标题 – 2012-07-19 03:12:09

回答

0

因为我试图改变该组的电子邮件地址,但是当我在组页手动试了一下不能是这就是为什么我得到400错误变化

+2

该解释没有意义... – 2013-08-19 23:43:40