"The client credentials are invalid" or "Missing required fields"

115 views
Skip to first unread message

Ahmet Durdu

unread,
Jun 30, 2015, 3:47:51 PM6/30/15
to im...@googlegroups.com
Hi,

I am trying to use my old imgur pro account. My account started at 01.12.2014. I uploaded many imut ages with my java program and I did not get any error until now. I can get pin but when  trying to exchange the pin with token the program throws exception. 





        
        String url = "https://api.imgur.com/oauth2/token";
        HttpClient client = HttpClientBuilder.create().build();
        HttpPost post = new HttpPost(url);
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        nameValuePairs.add(new BasicNameValuePair("client_id",  account.getClientId()));
        nameValuePairs.add(new BasicNameValuePair("client_secret", account.getClientSecret()));
        nameValuePairs.add(new BasicNameValuePair("grant_type", "pin"));
        nameValuePairs.add(new BasicNameValuePair("pin", account.getPin()));
        post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = client.execute(post);
        System.out.println("Response Code : "  + response.getStatusLine().getStatusCode());     // Response Code : 400
        BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    
the response is "{"data":{"error":"The client credentials are invalid","request":"\/oauth2\/token","method":"POST"},"success":false,"status":400}[\r][\n]" 




the second way is 

        url = new URL("https://api.imgur.com/oauth2/token");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        // create base64 image
        BufferedImage image = null;
        // read image
        conn.setDoOutput(true);
        conn.setDoInput(true);
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        conn.connect();
        StringBuilder stb = new StringBuilder();
        DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
        String parameters = "client_id=" + account.getClientId() + "&client_secret=" + account.getClientSecret() + "&grant_type=pin&pin=" + account.getPin();
        wr.writeBytes(parameters);
        wr.flush();
        BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));

the response  is {"data":{"error":"Missing required fields","request":"\/oauth2\/token","method":"GET"},"success":false,"status":400}



A few weeks ago I was using to upload images to imgur with second way but now I could not. Could you help me to find the problem ?

ps: I hope I can explain my problem clearly.

Thank you.
Reply all
Reply to author
Forward
0 new messages