-1

I am trying to send a request to oauth google to get a request token.i passed all the parameters required.here is the code.please help. The out put of the below code is a token provided by google to access its users private data.but i am getting the result that the page i requested is invalid.where did i go wrong? should i pass the scope also in the url?

public void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws IOException {
    try {  
          String oauthConsumerKey = "my key";
          String oauthSignatureMethod = "HMAC-SHA1";
          String oauthSignature = "my signature";
        // Send the request  
        URL url = new URL("https://www.google.com/accounts/OAuthGetRequestToken"+oauthConsumerKey+
        oauthSignatureMethod+oauthSignature);  
        URLConnection conn = url.openConnection();  
        conn.setDoOutput(true);  
        OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());  

        //write parameters   

        writer.flush();  

        // Get the response  
        StringBuffer answer = new StringBuffer();  
        BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));  
        String line;  
        while ((line = reader.readLine()) != null) {  
           System.out.println("\n" +line);

        }  

        writer.close();  
        reader.close();  
        //Output the response  


    } catch (MalformedURLException ex) {  
        ex.printStackTrace();  
    } catch (IOException ex) {  
        ex.printStackTrace();  
    }  
}

}

4

1 回答 1

0

call文档中所述OAuthGetRequestToken,您缺少一些必需的参数:

oauth_consumer_key     (required)
oauth_nonce            (required)
oauth_signature_method (required)
oauth_signature        (required)
oauth_timestamp        (required)
scope                  (required)
oauth_callback         (required)

您的查询 URL 还必须采用如下格式:

https://www.google.com/accounts/OAuthGetRequestToken?param1=value1&param2=value2&...

请注意,Google OAuth 1.0 API已被弃用,不应用于新项目:

重要提示:OAuth 1.0 已于 2012 年 4 月 20 日正式弃用。它将根据我们的弃用政策继续有效,但我们建议您尽快迁移到 OAuth 2.0。

此外,OAuth 2 流程更加简单,请查看Google 的文档

于 2012-07-13T08:39:09.687 回答