可能重复:
Twitter API not accepting callback URL for Android App
我正在尝试使用函数retrieveRequestToken(consumer,CALLBACK_URI)获取uri然后
登录twitter后使用访问密钥。但是retriveRequestToken()函数抛出异常
我给了互联网使用该应用程序的权限,但它不起作用。
Logcat:
01-07 19:26:24.589: D/in(581): check1
01-07 19:26:24.691: D/communication(581): 4
01-07 19:26:24.691: W/System.err(581): oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: null
01-07 19:26:24.691: W/System.err(581): at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:214)
01-07 19:26:24.702: W/System.err(581): at oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(AbstractOAuthProvider.java:69)
以下是代码段:
update = (Button) findViewById(R.id.update);
status = (TextView) findViewById(R.id.status);
private static final String CALLBACK_URI = "OauthTwitter://twitt";
private static final String REQUEST_TOKEN_URL = "https://api.twitter.com/oauth/request_token";
private static final String ACCESS_TOKEN_URL = "https://api.twitter.com/oauth/access_token";
private static final String AUTHORIZE_URL = "https://api.twitter.com/oauth/authorize";
private static CommonsHttpOAuthConsumer consumer;
private static DefaultOAuthProvider provider;
consumer = new CommonsHttpOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
provider = new DefaultOAuthProvider(REQUEST_TOKEN_URL,
ACCESS_TOKEN_URL, AUTHORIZE_URL);
update.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// showMyDialog();
try {
Log.d("in","check1");
String authUrl = provider.retrieveRequestToken(consumer,CALLBACK_URI);
Log.d("uri", authUrl);
startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse(authUrl)));
} catch (OAuthMessageSignerException e) {
// TODO Auto-generated catch block
Log.d("signerg","1");
e.printStackTrace();
} catch (OAuthNotAuthorizedException e) {
// TODO Auto-generated catch block
Log.d("Notauths","2");
e.printStackTrace();
} catch (OAuthExpectationFailedException e) {
// TODO Auto-generated catch block
Log.d("authExceg","3");
e.printStackTrace();
} catch (OAuthCommunicationException e) {
// TODO Auto-generated catch block
Log.d("communication","4");
e.printStackTrace();
}
}