【问题标题】:oauth get request token for google shows "The page you requested is invalid. "oauth get request token for google 显示“您请求的页面无效。”
【发布时间】:2012-07-13 16:44:19
【问题描述】:

我正在尝试向 oauth google 发送请求以获取请求令牌。我传递了所需的所有参数。这是代码。请帮助。 以下代码的输出是谷歌提供的用于访问其用户私人数据的令牌。但我得到的结果是我请求的页面无效。我哪里出错了? 我也应该在 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();  
    }  
}

}

【问题讨论】:

    标签: servlets oauth


    【解决方案1】:

    documentation of the OAuthGetRequestToken call 中所述,您缺少一些必需的参数:

    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 流程更简单,请查看the documentation at Google

    【讨论】:

      猜你喜欢
      • 2010-11-23
      • 1970-01-01
      • 1970-01-01
      • 2017-10-22
      • 1970-01-01
      • 2017-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多