Implement OAuth in Java

后端 未结 2 1584
时光取名叫无心
时光取名叫无心 2020-12-05 16:39

I made an an attempt to implement OAuth for my programming idea in Java, but I failed miserably. I don\'t know why, but my code doesn\'t work. Every time I run my program, a

相关标签:
2条回答
  • 2020-12-05 17:24

    Try remove the parameter "oauth_callback". It worked for me. The application I was working on is a web application.

    0 讨论(0)
  • 2020-12-05 17:31

    I know this is an old question but it seems it takes a bit of digging around to finally get a proper answer. This seems to be one of the top links in google too. Pages at dev.twitter.com lead to almost nowhere also. So here it goes. Look here for a code that properly handles it. It uses HttpCore, but it can be achieved with standard libraries.

    Making the story short.

    1. URLEncoder library in 1.6 (most likely then in Android too) doesn't conform to the RFC standard Twitter API requires. The code here seems to be countering the problem partially. Take a look at the source I linked to find the method handling it appropriately.
    2. While creating the base string parameter you are encoding each key value pair. It conforms to the guide at the twitter page. It is easier to append the encoded url and the whole created parameter string (key/value pairs)
    3. While creating the signature you are creating it against a keyspec object with the CONSUMER_KEY appended with "&" sign in request token method of the Twitter API.
    4. As far as for this code. For request token it doesn't seem to be important at all.

      connection.setRequestProperty("Accept-Charset", charset);  
      connection.setRequestProperty("Content-Type", "application/x-www-formurlencoded;charset="+ charset);  
      connection.setRequestProperty("User-Agent", "XXXX");  
      

      This one though, does connection.setRequestMethod(method);

    0 讨论(0)
提交回复
热议问题