万物似乎确定,但功能retrieveRequestToken()抛出“OAuthCommunicationException'例外 [英] Everythings seems ok but function retrieveRequestToken() throws 'OAuthCommunicationException' exception

查看:281
本文介绍了万物似乎确定,但功能retrieveRequestToken()抛出“OAuthCommunicationException'例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想,使其在叽叽喳喳的鸣叫建立一个Android应用程序。

我试图让使用功能retrieveRequestToken(消费者,CALLBACK_URI),URI,但它抛出OAuthCommunicationException'例外。
我给了互联网使用许可应用程序(我已经检查了)。我已经在registerd叽叽喳喳给读应用程序,写和直接的信息。

 的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通信空失败
在oauth.signpost.AbstractOAuthProvider.retrieveToken 01-07 192624.691 WSystem.err(581)(AbstractOAuthProvider.java214)
在oauth.signpost.AbstractOAuthProvider.retrieveRequestToken 01-07 192624.702 WSystem.err(581)(AbstractOAuthProvider.java69)

下面是code段

 更新=(按钮)findViewById(R.id.update);
        状态=(的TextView)findViewById(R.id.status);
私有静态最后弦乐CALLBACK_URI = OauthTwittertwitt;
私有静态最后弦乐REQUEST_TOKEN_URL = httpsapi.twitter.comoauthrequest_token;
私有静态最后弦乐ACCESS_TOKEN_URL = httpsapi.twitter.comoauthaccess_token;
私有静态最后弦乐AUTHORIZE_URL = httpsapi.twitter.comoauthauthorize;
私有静态CommonsHttpOAuthConsumer消费;
私有静态DefaultOAuthProvider提供商;
消费=新CommonsHttpOAuthConsumer(CONSUMER_KEY,CONSUMER_SECRET);
供应商=新DefaultOAuthProvider(REQUEST_TOKEN_URL,
                ACCESS_TOKEN_URL,AUTHORIZE_URL);
        update.setOnClickListener(新OnClickListener(){            @覆盖
            公共无效的onClick(视图v){
                 showMyDialog();                尝试{
                    Log.d(在,CHECK1);
                    字符串authUrl = provider.retrieveRequestToken(消费者,CALLBACK_URI);
                    Log.d(URI,authUrl);
                    startActivity(新意图(Intent.ACTION_VIEW,Uri.parse(authUrl)));
                }赶上(OAuthMessageSignerException E){
                     TODO自动生成catch块
                    Log.d(signerg,1);
                    e.printStackTrace();
                }赶上(OAuthNotAuthorizedException E){
                     TODO自动生成catch块
                    Log.d(Notauths,2);
                    e.printStackTrace();
                }赶上(OAuthExpectationFailedException E){
                     TODO自动生成catch块
                    Log.d(authExceg,3);
                    e.printStackTrace();
                }赶上(OAuthCommunicationException E){
                     TODO自动生成catch块
                    Log.d(通信,4);
                    e.printStackTrace();
                }            }


解决方案

这是通过在主线程异常的网络造成的。尝试在一个线程运行的OAuth code:

 新主题(新的Runnable(){
                公共无效的run(){
                    字符串authUrl = provider.retrieveRequestToken(消费者,CALLBACK_URI);
                }
              })。开始();

I am trying to build an android app so that it tweets in twitter.
I am trying to get uri using the function retrieveRequestToken(consumer,CALLBACK_URI) but it throws 'OAuthCommunicationException' exception. I gave the internet uses permission for the application( i have checked it ).I have registerd the app in twitter giving read,write and direct messages.

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)

Here is the code snippet

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();
                }

            }

解决方案

This is caused by a network on main thread exception. Try running the oauth code on a thread:

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

这篇关于万物似乎确定,但功能retrieveRequestToken()抛出“OAuthCommunicationException'例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆