gpt4 book ai didi

android - 一切似乎没问题,但函数 retrieveRequestToken() 抛出 'OAuthCommunicationException' 异常

转载 作者:太空狗 更新时间:2023-10-29 12:54:05 25 4
gpt4 key购买 nike

我正在尝试构建一个 Android 应用程序,以便它在 Twitter 上发推文。
我正在尝试使用函数 retrieveRequestToken(consumer,CALLBACK_URI) 获取 uri,但它抛出“OAuthCommunicationException”异常。我为该应用程序授予了互联网使用许可(我已经检查过了)。我已经在 Twitter 上注册了该应用程序,提供读、写和直接消息。

Logcat
01-07 192624.589 Din(581) check1
01-07 192624.691 Dcommunication(581) 4
01-07 192624.691 WSystem.err(581) oauth.signpost.exception.OAuthCommunicationException Communication with the service provider failed null
01-07 192624.691 WSystem.err(581) at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java214)
01-07 192624.702 WSystem.err(581) at oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(AbstractOAuthProvider.java69)

这是代码 fragment

update = (Button) findViewById(R.id.update);
status = (TextView) findViewById(R.id.status);
private static final String CALLBACK_URI = OauthTwittertwitt;
private static final String REQUEST_TOKEN_URL = httpsapi.twitter.comoauthrequest_token;
private static final String ACCESS_TOKEN_URL = httpsapi.twitter.comoauthaccess_token;
private static final String AUTHORIZE_URL = httpsapi.twitter.comoauthauthorize;
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();
}

}

最佳答案

这是由网络上的主线程异常引起的。尝试在线程上运行 oauth 代码:

          new Thread(new Runnable() {
public void run() {
String authUrl = provider.retrieveRequestToken(consumer,CALLBACK_URI);
}
}).start();

关于android - 一切似乎没问题,但函数 retrieveRequestToken() 抛出 'OAuthCommunicationException' 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8779186/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com