I am getting these error when retrieving ucoz.api.ru (oauth 1.0a) token using scribe library oauth (4.2.0) on android :
Caused by: com.github.scribejava.core.exceptions.OAuthException: Response body is incorrect. Can't extract token and secret from this:
'{"oauth_token":"NAzoveaGm5XIlBvLcLRxUvamEK8P2.BAlQZ.M.aV","oauth_token_secret":"SJsqC0IfFAKS3BkdauQ3bY4ha01PDHTlFIy7GSro","oauth_callback_confirmed":"true"}'
at com.github.scribejava.core.extractors.AbstractOAuth1TokenExtractor.extract(AbstractOAuth1TokenExtractor.java:42) at com.github.scribejava.core.extractors.AbstractOAuth1TokenExtractor.extract(AbstractOAuth1TokenExtractor.java:32) at com.github.scribejava.core.extractors.AbstractOAuth1TokenExtractor.extract(AbstractOAuth1TokenExtractor.java:19) at com.github.scribejava.core.oauth.OAuth10aService.getRequestToken(OAuth10aService.java:49) at com.vasyaevstropov.oauth10test.MainActivity.request(MainActivity.java:96) at com.vasyaevstropov.oauth10test.MainActivity$1$1.doInBackground(MainActivity.java:61) at com.vasyaevstropov.oauth10test.MainActivity$1$1.doInBackground(MainActivity.java:53) at android.os.AsyncTask$2.call(AsyncTask.java:288) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) at java.lang.Thread.run(Thread.java:841)
My source code:
final OAuth10aService service = new ServiceBuilder(CONSUMER_KEY)
.apiSecret(CONSUMER_SECRET)
.debug()
.build(UcozApi.instance());
final Scanner in = new Scanner(System.in);
// Obtain the Request Token
final OAuth1RequestToken requestToken = service.getRequestToken(); // <<--- Error is in this place
System.out.println(service.getAuthorizationUrl(requestToken));
final String oauthVerifier = in.nextLine();
// Trade the Request Token and Verfier for the Access Token
OAuth1AccessToken accessToken = null;
try {
accessToken = service.getAccessToken(requestToken, oauthVerifier);
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
Ucozapi module:
public class UcozApi extends com.github.scribejava.core.builder.api.DefaultApi10a {
private static final String AUTHORIZE_URL = "http://uapi.ucoz.com/accounts/oauthauthorizetoken=%s";
private static final String REQUEST_TOKEN_RESOURCE = "http://uapi.ucoz.com/accounts/oauthgetrequesttoken";
private static final String ACCESS_TOKEN_RESOURCE = "http://uapi.ucoz.com/accounts/oauthgetaccesstoken";
protected UcozApi() {
}
private static final UcozApi INSTANCE = new UcozApi();
public static UcozApi instance() {
return INSTANCE;
}
@Override
public String getAccessTokenEndpoint() {
return ACCESS_TOKEN_RESOURCE;
}
@Override
public String getRequestTokenEndpoint() {
return REQUEST_TOKEN_RESOURCE;
}
@Override
public String getAuthorizationUrl(OAuth1RequestToken requestToken) {
return String.format(AUTHORIZE_URL, requestToken.getToken());
}
}
Can somebody help me?
I answer my question. This code will work good with scribe-java library:
MainActivity:
UcozApi
OAuth1RequestUcozTokenExtractor
OAuth1AccessUcozTokenExtractor
AbstractOauth1UcozTokenExtractor