Java 签名\无效数据库\字符串

Java 签名\无效数据库\字符串,java,google-app-engine,oauth,google-api,2-legged,Java,Google App Engine,Oauth,Google Api,2 Legged,嗨,我正在制作一个谷歌应用程序,在其中我向谷歌API发送请求。我正在尝试实现2legged OAuth1.0以获取请求令牌(我遵循此步骤) 在这个链接中,我向/accounts/oauth/GetRequesttoken发送了APAST请求。下面是我发送post请求的servlet代码。注释很好,请阅读: package org.ritesh; //import classes import java.io.BufferedInputStream; import j

嗨,我正在制作一个谷歌应用程序,在其中我向谷歌API发送请求。我正在尝试实现2legged OAuth1.0以获取请求令牌(我遵循此步骤)

在这个链接中,我向/accounts/oauth/GetRequesttoken发送了APAST请求。下面是我发送post请求的servlet代码。注释很好,请阅读:

   package org.ritesh;
    //import classes
    import java.io.BufferedInputStream;
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.OutputStreamWriter;
    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.net.URLEncoder;

    import javax.servlet.http.*;

    import com.google.gdata.client.authn.oauth.GoogleOAuthParameters;

    @SuppressWarnings("serial")
    public class HelloWorldServlet extends HttpServlet {
method for handling get request    
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
                throws IOException {

            resp.setContentType("text/plain");
            resp.getWriter().println("Hello, world");

//setting oauth_version parameter to 1.0      

        String datastring=URLEncoder.encode("oauth_version", "UTF-8")+"="+URLEncoder.encode("1.0", "UTF-8");

 //setting oauth_nonce a unique value so assigned a time stamp     

      datastring+="&"+URLEncoder.encode("oauth_nonce", "UTF-8")+"="+URLEncoder.encode(System.currentTimeMillis()+"","UTF-8");
        //setting parameter oauth_timestamp to current time in setting

      datastring+="&"+URLEncoder.encode("oauth_timestamp", "UTF-8")+"="+URLEncoder.encode(System.currentTimeMillis()/1000+"","UTF-8");

//its my domain name i am hosting my app on domain iriteshmehandiratta.appspot.com

        datastring+="&"+URLEncoder.encode("oauth_consumer_key","UTF-8")+"="+URLEncoder.encode("iriteshmehandiratta.appspot.com","UTF-8");
  //my .pem file contain RSA fingerprints so i include RSA-SHA1 for //oauth_signature_method    

        datastring+="&"+URLEncoder.encode("oauth_signature_method","UTF-8")+"="+URLEncoder.encode("RSA-SHA1", "UTF-8"); 
  //consumer_secret that i got when i successfully registered my app  on google Manage domain link

        datastring+="&"+URLEncoder.encode("oauth_signature", "UTF-8")+"="+URLEncoder.encode("eOcmMdWaO2O14JyK1TbYPS09", "UTF-8");
    //setting oauth_callback parameter

    datastring+="&"+URLEncoder.encode("oauth_callback","UTF-8")+"="+URLEncoder.encode("https://www.iriteshmehandiratta.appspot.com/authsub","UTF-8");

    datastring+="&"+URLEncoder.encode("scope","UTF-8")+"="+URLEncoder.encode("http://www.google.com/calendar/feeds","UTF-8");


    URL url=new URL("https://www.google.com/accounts/OAuthGetRequestToken?"+datastring); 

            HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();

            urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

            urlConnection.setRequestProperty("Authorization", "OAuth");

            urlConnection.setRequestMethod("POST");

            urlConnection.setDoOutput(true);

            BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));

              resp.getWriter().println( urlConnection.getResponseCode());

               String xx="";

               String xx1="";

               while((xx1=in.readLine()) != null)

               {
                   xx+=xx1;


               }
               resp.getWriter().println(xx);

        }
    }
当我运行此命令时,我希望响应如下

oauth_token=ab3cd9j4ks73hf7g&oauth_token_secret=ZXhhbXBsZS5jb20&oauth_callback_confirmed=true
但我得到的回应是:

signature_invalidbase_string:POST&https%3A%2F%2Fwww.google.com%2Faccounts%2FOAuthGetRequestToken&oauth_callback%3Dhttps%253A%252F%252Fwww.iriteshmehandiratta.appspot.com%252Fauthsub%26oauth_consumer_key%3Diriteshmehandiratta.appspot.com%26oauth_nonce%3D1357576190878%26oauth_signature_method%3DRSA-SHA1%26oauth_timestamp%3D1357576190%26oauth_version%3D1.0%26scope%3Dhttp%253A%252F%252Fwww.google.com%252Fcalendar%252Ffeeds 

如果我错了,请告诉我如何纠正此问题:

我建议您尝试使用该库。在AppEngine上已经过测试。

您忘了提到问题所在@PradeepSimha我更新了问题并指定了我遇到的错误。请帮助我如何更正它。