JerryBlight / oauth

Automatically exported from code.google.com/p/oauth
0 stars 0 forks source link

Scribe oauth issue #252

Open a4200 opened 9 years ago

a4200 commented 9 years ago

getting error :+1: Exception in thread "main" org.scribe.exceptions.OAuthException: Response body is incorrect. Can't extract token and secret from this: 'oauth_problem=verifier_invalid' at org.scribe.extractors.TokenExtractorImpl.extract(TokenExtractorImpl.java:41)

problem is here: Token accessToken = service.getAccessToken(requestToken, verifier);

how to slove this ???? full code is: public static void main(String[] args) {

    final String MAGENTO_API_KEY = "1e4ba1c18fab07ce17297c468236c475";
    final String MAGENTO_API_SECRET = "d39d101b5daa21e4735c1a85ea059d94";
    final String MAGENTO_REST_API_URL = "http://localhost/magento/api/rest/";

    OAuthService service = new ServiceBuilder()
    .provider(MagentoThreeLeggedOAuth.class)
    .apiKey(MAGENTO_API_KEY)
    .apiSecret(MAGENTO_API_SECRET)
    .callback("http://sasken.com/MagentoScribe").build();
   // .build();
    System.out.println("" + service.getVersion());
    Scanner in = new Scanner(System.in);
    System.out.println("Magento's OAuth Workflow");
    System.out.println();
 // Obtain the Request Token
    System.out.println("Fetching the Request Token...");
    Token requestToken = service.getRequestToken();
    System.out.println("Got the Request Token!" +requestToken);
    System.out.println();
    System.out.println("Fetching the Authorization URL...");
   // MagentoThreeLeggedOAuth serv = new MagentoThreeLeggedOAuth();
   // System.out.println("seervice class:"+service.getClass());

   String authorizationUrl = service.getAuthorizationUrl(requestToken);

  String word ="";
 String token1 = requestToken.toString();
 System.out.println("token1 :" + token1.length());
 String[] strArray = token1.split(",");
 for(int i=0;i<= token1.length();i++)
 {
      word = strArray[1];
     //word = word.substring(1);
     word = word.replaceAll("]", "");

 }

 System.out.println("word vale is :" + word);

    System.out.println("Got the Authorization URL!");
    System.out.println("Now go and authorize Main here:");
    System.out.println(authorizationUrl);
    System.out.println("And paste the authorization code here");
    System.out.print(">>");

   // String authUrl = serv.getAuthorizationUrl(requestToken);
   // System.out.println("authUrl::"+ authUrl);
   // Verifier verifier = new Verifier(authUrl);
//  Verifier verifier = new Verifier(in.nextLine());

   Verifier verifier = new Verifier(word);
 //   System.out.println("varifier::" +verifier.toString());
    //   Verifier verifier = new Verifier("7d4fa4e31d15fbc7b3c4e5eee936eb63");
     System.out.println("Trading the Request Token for an Access Token..." + requestToken );
     System.out.println("varifier::" + verifier.getValue());
     System.out.println("requestToken:" + requestToken.getToken());
        Token accessToken = service.getAccessToken(requestToken, verifier);
        System.out.println("Got the Access Token!");
        System.out.println("(if your curious it looks like this: "
                + accessToken + " )");
        System.out.println();
        OAuthRequest request = new OAuthRequest(Verb.GET, MAGENTO_REST_API_URL+ "/products?limit=2");
        service.signRequest(accessToken, request);
        Response response = request.send();
        System.out.println();
        System.out.println(response.getCode());
        System.out.println(response.getBody());
                System.out.println();

}
a4200 commented 9 years ago

any one help??