Getting Error 400 while Requesting an Access token (Java)

新規投稿

コメント

8件のコメント

  • bkhane
    URL obj = new URL(url);
    			HttpsURLConnection connection = (HttpsURLConnection) obj.openConnection();
    			connection.setRequestMethod("POST");
    			 connection.setRequestProperty("grant_type=","authorization_code");
    			 connection.setRequestProperty("code", code);
    			 connection.setRequestProperty("client_id", ConfigAuth.client_id);
    			 connection.setRequestProperty("client_secret", ConfigAuth.client_secret);
    			 connection.setRequestProperty("Content-Length", "100");
    			 System.out.println("\nSending 'GET' request to URL : " + url);
    		        System.out.println("Response code:" + connection.getResponseCode());
    			        System.out.println("Response message:" + connection.getResponseMessage());
    			            // Read the response:
    			            BufferedReader reader = new BufferedReader(new InputStreamReader(
    			            connection.getInputStream()));
    			            String line;
    			            StringBuffer response = new StringBuffer();
    			            while ((line = reader.readLine()) != null) {
    			                response.append(line);
    			            }
    			            reader.close();
    			            System.out.println(response.toString());

     this is my second approach. Now I get Error code 411 and not 400. Any Ideas on how to fix that? I tried adding 

    connection.SetRequestProperty("Content-Length", "0"); but that didn't do any good either. 

    0
    コメントアクション Permalink
  • cbetta

     hey there, have you considered using our SDK? A guide is available for it here.

     

    https://developer.box.com/docs/authenticate-with-oauth-2

    0
    コメントアクション Permalink
  • bkhane

    I've tried that but that didn't seem to work. 

    BoxAPIConnection works with a developer token, but if I use client ID, Secret and the authorization token then it is not creating a working connection for me. So I tried requesting an actual access token so I could create a working BoxAPIConnection. If I execute the following I get an Error 400. That's why I tried a different approach. I really could use some help!

     get("/start", (req, res) -> {
    
    			 
    			  
    		// Redirect user to login with Box
    			String box_redirect = ConfigAuth.box_redirect
    			  + "?response_type=code"
    			  + "&client_id=" + ConfigAuth.client_id 
    			  + "&client_secret=" + ConfigAuth.client_secret
    			  + "&redirect_uri=" + ConfigAuth.redirect_uri;
    				res.redirect(box_redirect);
    				return "redirecting...";
    
    				  
    				  
    				        		
    				  
    				});
    			 
    			 
    		 get("/return", (req, res) -> {
    			 // Capture auth code 
    			  String code = req.queryParams("code");
    			  
    		System.out.println(code);
     BoxAPIConnection client = new BoxAPIConnection(ConfigAuth.client_id,ConfigAuth.client_secret,code);
    				  
    				  
    			  BoxFolder rootFolder = BoxFolder.getRootFolder(client);
    			  FileInputStream stream = new FileInputStream(ConfigAuth.file_path);
    			  BoxFile.Info fileinfo = rootFolder.uploadFile(stream, "tax.txt");
    			  stream.close();
    			  return "Display Page"; 
    			  
    		 });

     

    0
    コメントアクション Permalink
  • Kourtney

     would you be able to provide the full body error response? I'm looking for the Box request ID so I can take a look at our backend logs. Alternatively, you can open a support case with all the details so we can help you further investigate. 

    0
    コメントアクション Permalink
  • bkhane

    I've opened a ticket with my client ID but I'm not sure where I can find the box Request ID.

    0
    コメントアクション Permalink
  • Kourtney

     no worries! what is the ticket number? I wanna grab it so you can work with me directly. If you could also provide an example date/time/timezone you received the error that'd be most helpful! 

    0
    コメントアクション Permalink
  • bkhane

    My ticket number: 1813690

    Last time I got the error was 7.42 3rd of January 2018 (central European time)

    0
    コメントアクション Permalink
  • Kourtney

     thank you! Let me do some digging and I'll follow up with you in the ticket. 

    0
    コメントアクション Permalink

サインインしてコメントを残してください。