LinkedIn:oauth.signpost.exception.OAuthCommunicationException:与服务提供者的通信失败:空 [英] Linkedin : oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: null

查看:574
本文介绍了LinkedIn:oauth.signpost.exception.OAuthCommunicationException:与服务提供者的通信失败:空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要访问我的Andr​​oid应用程序的LinkedIn个人资料。我用下面的code这是工作的罚款在Android设备上,但要坠毁在模拟器。开不知道哪里出了问题。我的code是如下。

Config.java

 公共类配置{

    公共静态字符串LINKEDIN_CONSUMER_KEY =75rbbjsc94argh;
    公共静态字符串LINKEDIN_CONSUMER_SECRET =G85WTKgcIijk4U6Yu;
    公共静态字符串scopeParams = "rw_nus+r_basicprofile+r_fullprofile+r_emailaddress+r_network+r_contactinfo+rw_groups+rw_company_admin";

    公共静态字符串OAUTH_CALLBACK_SCHEME =X-oauthflow  -  LinkedIn;
    公共静态字符串OAUTH_CALLBACK_HOST =回调;
    //公共静态字符串OAUTH_CALLBACK_URL = OAUTH_CALLBACK_SCHEME +://+ OAUTH_CALLBACK_HOST;
    公共静态字符串OAUTH_CALLBACK_URL =X-oauthflow  -  LinkedIn://回调;
}
 

LinkedInSampleActivity.java

 公共类LinkedInSampleActivity延伸活动{
    按钮的登录;
    巴顿份额;
    的EditText等;
    TextView的名称;
    ImageView的照片;
    公共静态最后弦乐OAUTH_CALLBACK_HOST =litestcalback;

    最后LinkedInOAuthService oAuthService = LinkedInOAuthServiceFactory
            .getInstance()。createLinkedInOAuthService(
                    Config.LINKEDIN_CONSUMER_KEY,Config.LINKEDIN_CONSUMER_SECRET,Config.scopeParams);
    最后LinkedInApiClientFactory厂= LinkedInApiClientFactory
            .newInstance(Config.LINKEDIN_CONSUMER_KEY,
                    Config.LINKEDIN_CONSUMER_SECRET);
    LinkedInRequestToken liToken;
    LinkedInApiClient客户端;
    LinkedInAccessToken accessToken = NULL;

    @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);

        份额=(按钮)findViewById(R.id.share);
        名称=(TextView中)findViewById(R.id.name);
        等=(EditText上)findViewById(R.id.et_share);
        登录=(按钮)findViewById(R.id.login);
        照片=(ImageView的)findViewById(R.id.photo);

        login.setOnClickListener(新OnClickListener(){
            @覆盖
            公共无效的onClick(视图v){
                linkedInLogin();
            }
        });
    }

    私人无效linkedInLogin(){
        ProgressDialog progressDialog =新ProgressDialog(
                LinkedInSampleActivity.this);

        LinkedinDialog D =新LinkedinDialog(LinkedInSampleActivity.this,
                progressDialog);
        d.show();

        //设置回调监听器来获得oauth_verifier值
        d.setVerifierListener(新OnVerifyListener(){
            @覆盖
            公共无效onVerify(字符串验证){
                尝试 {
                    Log.i(LinkedinSample,验证:+验证);

                    accessToken = LinkedinDialog.oAuthService
                            .getOAuthAccessToken(LinkedinDialog.liToken,
                                    验证);
                    LinkedinDialog.factory.createLinkedInApiClient(accessToken);
                    客户端= factory.createLinkedInApiClient(accessToken);


                    client.postNetworkUpdate(测试由Umesh制作的Andr​​oid应用程序!LinkedIn的墙后);


                    人P2 = client.getProfileForCurrentUser(EnumSet.of(ProfileField.ID));
                    者P = client.getProfileById(p2.getId(),EnumSet.of(
                    ProfileField.FIRST_NAME,
                    ProfileField.LAST_NAME,
                    ProfileField.SKILLS,
                    ProfileField.HEADLINE,
                    ProfileField.SUMMARY,
                    ProfileField.LANGUAGES,
                    ProfileField.LANGUAGES_LANGUAGE_NAME,
                    ProfileField.LANGUAGES_PROFICIENCY_NAME,
                    ProfileField.LANGUAGES_LANGUAGE,
                    ProfileField.HONORS,
                    ProfileField.INTERESTS,
                    ProfileField.POSITIONS,
                    ProfileField.EDUCATIONS,
                    ProfileField.INDUSTRY,
                    ProfileField.API_STANDARD_PROFILE_REQUEST,
                    ProfileField.PICTURE_URL,
                    ProfileField.PUBLIC_PROFILE_URL));

                    name.setText(欢迎+ p.getFirstName()++ p.getLastName());

                    Log.i(LinkedinSample,ln_access_token:+ accessToken.getToken());
                    Log.i(LinkedinSample,ln_access_token:+ accessToken.getTokenSecret());
                    Log.i(姓,:+ p.getFirstName());
                    Log.i(名字,:+ p.getLastName());
                    Log.i(用户摘要,:+ p.getSummary());
                    Log.i(标题,:+ p.getHeadline());
                    Log.i(利息,:+ p.getInterests());

                    // ------------------------------------------------ ----

                    对于(位置位置:p.getPositions()getPositionList())
                    {
                        Log.i(位置,:+ position.getTitle());
                        Log.i(补偿,:+ position.getCompany()的getName());

                    }

                    对于(教育教育:p.getEducations()getEducationList()。)
                    {
                        Log.i(度,:+ education.getDegree());
                        Log.i(学校名称,:+ education.getSchoolName());

                    }
                    Log.i(语言,:);
                    对于(语言的语言:p.getLanguages​​()getLanguageList())
                    {
                        Log.i(,:+ language.getLanguage()的getName());
                    }
                    Log.i(技能,:);
                    对于(技能技巧:p.getSkills()getSkillList())
                    {
                        Log.i(,:+ skill.getSkill()的getName());
                    }
                    Log.i(荣誉,:+ p.getHonors());
                    // ------------------------------------------------ ----

                    name.setVisibility(0);
                    login.setVisibility(4);
                    share.setVisibility(0);
                    et.setVisibility(0);

                }赶上(例外五){
                    Log.i(LinkedinSample,错误得到验证);
                    e.printStackTrace();
                }
            }
        });

        //设置进度对话框
        progressDialog.setMessage(载入中...);
        progressDialog.setCancelable(真正的);
        progressDialog.show();
    }
}
 

LinkedinDialog.java

 公共类LinkedinDialog扩展对话框{
    私人ProgressDialog progressDialog = NULL;

    公共静态LinkedInApiClientFactory厂;
    公共静态LinkedInOAuthService oAuthService;
    公共静态LinkedInRequestToken liToken;

    //构造一个新的LinkedIn对话框

    公共LinkedinDialog(上下文的背景下,ProgressDialog progressDialog){
        超(上下文);
        this.progressDialog = progressDialog;
    }

    @覆盖
    保护无效的onCreate(包savedInstanceState){
        requestWindowFeature(Window.FEATURE_NO_TITLE); //必须超之前调用。
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.ln_dialog);
        setWebView();
    }

    //设置web视图。
    私人无效setWebView(){
        LinkedinDialog.oAuthService = LinkedInOAuthServiceFactory.getInstance()
                .createLinkedInOAuthService(Config.LINKEDIN_CONSUMER_KEY,
                        Config.LINKEDIN_CONSUMER_SECRET);
        LinkedinDialog.factory = LinkedInApiClientFactory.newInstance(
                Config.LINKEDIN_CONSUMER_KEY,Config.LINKEDIN_CONSUMER_SECRET);

        LinkedinDialog.liToken = LinkedinDialog.oAuthService.getOAuthRequestToken(Config.OAUTH_CALLBACK_URL);

        的WebView mWebView =(web视图)findViewById(R.id.webkitWebView1);
        mWebView.getSettings()setJavaScriptEnabled(真)。

        Log.i(LinkedinSample,LinkedinDialog.liToken.getAuthorizationUrl());
        mWebView.loadUrl(LinkedinDialog.liToken.getAuthorizationUrl());
        mWebView.setWebViewClient(新HelloWebViewClient());

        mWebView.setPictureListener(新PictureListener(){
            @覆盖
            公共无效onNewPicture(web视图来看,画中画){
                如果(progressDialog =空&安培;!&安培; progressDialog.isShowing()){
                    progressDialog.dismiss();
                }

            }
        });

    }

    //的WebView客户端内部URL加载

    类HelloWebViewClient扩展WebViewClient {
        @覆盖
        公共布尔shouldOverrideUrlLoading(web视图查看,字符串URL){
            如果(url.contains(Config.OAUTH_CALLBACK_URL)){
                开放的我们的uri = Uri.parse(URL);
                串验证= uri.getQueryParameter(oauth_verifier);
                取消();
                对于(OnVerifyListener D:听众){
                    //调用监听方法
                    d.onVerify(验证);
                }
            }否则,如果(url.contains(https://www.linkedin.com/uas/oauth/redorangetechnologies.com)){
                取消();
            } 其他 {
                Log.i(LinkedinSample,URL:+网址);
                view.loadUrl(URL);
            }

            返回true;
        }
    }

    / **
     *听众的名单。
     * /
    私人列表< OnVerifyListener>听众=新的ArrayList< OnVerifyListener>();

    / **
     *注册时的身份验证完成后要调用的回调。
     *
     * @参数数据
     *将运行回调
     * /
    公共无效setVerifierListener(OnVerifyListener数据){
        listeners.add(数据);
    }

    / **
     *侦听器oauth_verifier。
     * /
    接口OnVerifyListener {
        / **
         *当认证完成后调用。
         *
         * @参数验证
         * oauth_verifier code。
         * /
        公共无效onVerify(字符串验证);
    }
}
 

应用程序崩溃,在点击登录按钮,错误显示了setWebView();在LinkedinDialog类。

以下是logcat的:

  01-17 15:50:​​06.513:E / AndroidRuntime(2544):致命异常:主要
01-17 15:50:​​06.513:E / AndroidRuntime(2544):com.google code.linkedinapi.client.oauth.LinkedInOAuthServiceException:oauth.signpost.exception.OAuthCommunicationException:与服务提供者的通信失败:空
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在com.google.$c$c.linkedinapi.client.oauth.LinkedInOAuthServiceImpl.getOAuthRequestToken(LinkedInOAuthServiceImpl.java:205)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在com.mukesh.linkedin.LinkedinDialog.setWebView(LinkedinDialog.java:65)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在com.mukesh.linkedin.LinkedinDialog.onCreate(LinkedinDialog.java:54)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在android.app.Dialog.dispatchOnCreate(Dialog.java:340)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在android.app.Dialog.show(Dialog.java:253)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在com.mukesh.linkedin.LinkedInSampleActivity.linkedInLogin(LinkedInSampleActivity.java:100)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在com.mukesh.linkedin.LinkedInSampleActivity.access $ 0(LinkedInSampleActivity.java:94)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在com.mukesh.linkedin.LinkedInSampleActivity $ 1.onClick(LinkedInSampleActivity.java:69)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在android.view.View.performClick(View.java:3480)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在android.view.View $ PerformClick.run(View.java:13983)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在android.os.Handler.handleCallback(Handler.java:605)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在android.os.Handler.dispatchMessage(Handler.java:92)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在android.os.Looper.loop(Looper.java:137)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在android.app.ActivityThread.main(ActivityThread.java:4340)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在java.lang.reflect.Method.invokeNative(本机方法)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在java.lang.reflect.Method.invoke(Method.java:511)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:784)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在dalvik.system.NativeStart.main(本机方法)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):由:oauth.signpost.exception.OAuthCommunicationException:与服务提供者的通信失败:空
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:214)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(AbstractOAuthProvider.java:69)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在com.google.$c$c.linkedinapi.client.oauth.LinkedInOAuthServiceImpl.getOAuthRequestToken(LinkedInOAuthServiceImpl.java:196)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):18 ...更多
01-17 15:50:​​06.513:E / AndroidRuntime(2544):由:android.os.NetworkOnMainThreadException
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在android.os.StrictMode $ AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1084)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在java.net.InetAddress.lookupHostByName(InetAddress.java:391)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在java.net.InetAddress.getAllByName(InetAddress.java:220)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在libcore.net.http.HttpConnection< INIT>(HttpConnection.java:71)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在libcore.net.http.HttpConnection< INIT>(HttpConnection.java:50)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在libcore.net.http.HttpConnection $ Address.connect(HttpConnection.java:351)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:460)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在libcore.net.http.HttpsURLConnectionImpl $ HttpsEngine.connect(HttpsURLConnectionImpl.java:432)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在libcore.net.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:164)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在oauth.signpost.basic.DefaultOAuthProvider.sendRequest(DefaultOAuthProvider.java:48)
01-17 15:50:​​06.513:E / AndroidRuntime(2544):在oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:177)
 

解决方案

的setContentView()中的onCreate后添加下面的函数()。

 如果(android.os.Build.VERSION.SDK_INT> 9){
        。StrictMode.ThreadPolicy政策=新StrictMode.ThreadPolicy.Builder()permitAll()建(); StrictMode.setThreadPolicy(政策);
        }
 

这为我工作。希望它会为你工作。

I am going to access linkedin profile in my android app. I used the below code which is working fine on android devices, but getting crashed on emulator. Does't know where is the problem. My code is below.

Config.java

public class Config {

    public static String LINKEDIN_CONSUMER_KEY = "75rbbjsc94argh";
    public static String LINKEDIN_CONSUMER_SECRET = "G85WTKgcIijk4U6Yu";
    public static String scopeParams = "rw_nus+r_basicprofile+r_fullprofile+r_emailaddress+r_network+r_contactinfo+rw_groups+rw_company_admin";

    public static String OAUTH_CALLBACK_SCHEME = "x-oauthflow-linkedin";
    public static String OAUTH_CALLBACK_HOST = "callback";
    //public static String OAUTH_CALLBACK_URL = OAUTH_CALLBACK_SCHEME + "://" + OAUTH_CALLBACK_HOST;
    public static String OAUTH_CALLBACK_URL = "x-oauthflow-linkedin://callback";
}

LinkedInSampleActivity.java

public class LinkedInSampleActivity extends Activity {
    Button login;
    Button share;
    EditText et;
    TextView name;
    ImageView photo;
    public static final String OAUTH_CALLBACK_HOST = "litestcalback";

    final LinkedInOAuthService oAuthService = LinkedInOAuthServiceFactory
            .getInstance().createLinkedInOAuthService(
                    Config.LINKEDIN_CONSUMER_KEY,Config.LINKEDIN_CONSUMER_SECRET, Config.scopeParams);
    final LinkedInApiClientFactory factory = LinkedInApiClientFactory
            .newInstance(Config.LINKEDIN_CONSUMER_KEY,
                    Config.LINKEDIN_CONSUMER_SECRET);
    LinkedInRequestToken liToken;
    LinkedInApiClient client;
    LinkedInAccessToken accessToken = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        share = (Button) findViewById(R.id.share);
        name = (TextView) findViewById(R.id.name);
        et = (EditText) findViewById(R.id.et_share);
        login = (Button) findViewById(R.id.login);
        photo = (ImageView) findViewById(R.id.photo);

        login.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                linkedInLogin();
            }
        });
    }

    private void linkedInLogin() {
        ProgressDialog progressDialog = new ProgressDialog(
                LinkedInSampleActivity.this);

        LinkedinDialog d = new LinkedinDialog(LinkedInSampleActivity.this,
                progressDialog);
        d.show();

        // set call back listener to get oauth_verifier value
        d.setVerifierListener(new OnVerifyListener() {
            @Override
            public void onVerify(String verifier) {
                try {
                    Log.i("LinkedinSample", "verifier: " + verifier);

                    accessToken = LinkedinDialog.oAuthService
                            .getOAuthAccessToken(LinkedinDialog.liToken,
                                    verifier);
                    LinkedinDialog.factory.createLinkedInApiClient(accessToken);
                    client = factory.createLinkedInApiClient(accessToken);


                    client.postNetworkUpdate("Testing by Umesh!!! LinkedIn wall post from Android app");


                    Person p2 = client.getProfileForCurrentUser(EnumSet.of(ProfileField.ID)); 
                    Person p = client.getProfileById(p2.getId(), EnumSet.of(
                    ProfileField.FIRST_NAME,
                    ProfileField.LAST_NAME,
                    ProfileField.SKILLS,
                    ProfileField.HEADLINE,
                    ProfileField.SUMMARY,
                    ProfileField.LANGUAGES,
                    ProfileField.LANGUAGES_LANGUAGE_NAME,
                    ProfileField.LANGUAGES_PROFICIENCY_NAME,
                    ProfileField.LANGUAGES_LANGUAGE,
                    ProfileField.HONORS,
                    ProfileField.INTERESTS,
                    ProfileField.POSITIONS,
                    ProfileField.EDUCATIONS,
                    ProfileField.INDUSTRY,
                    ProfileField.API_STANDARD_PROFILE_REQUEST,
                    ProfileField.PICTURE_URL,
                    ProfileField.PUBLIC_PROFILE_URL));

                    name.setText("Welcome " + p.getFirstName() + " "+ p.getLastName());

                    Log.i("LinkedinSample","ln_access_token: " + accessToken.getToken());
                    Log.i("LinkedinSample","ln_access_token: " + accessToken.getTokenSecret());
                    Log.i("FirstName"," : " + p.getFirstName());
                    Log.i("LastName"," : " + p.getLastName());
                    Log.i("User Summary"," : " + p.getSummary());
                    Log.i("Headline"," : " + p.getHeadline());
                    Log.i("Interest"," : "+p.getInterests());

                    //----------------------------------------------------

                    for (Position position:p.getPositions().getPositionList())
                    {
                        Log.i("position "," : " + position.getTitle());
                        Log.i("comp "," : " + position.getCompany().getName());

                    }

                    for (Education education:p.getEducations().getEducationList()) 
                    {
                        Log.i("Degree "," : "+ education.getDegree());
                        Log.i("School name "," : "+ education.getSchoolName());

                    }
                    Log.i("Language "," : ");
                    for(Language language:p.getLanguages().getLanguageList())
                    {
                        Log.i(""," : "+language.getLanguage().getName());
                    }
                    Log.i("Skill "," : ");
                    for(Skill skill:p.getSkills().getSkillList())
                    {
                        Log.i(""," : "+skill.getSkill().getName());
                    }
                    Log.i("Honor"," : "+p.getHonors());
                    //----------------------------------------------------

                    name.setVisibility(0);
                    login.setVisibility(4);
                    share.setVisibility(0);
                    et.setVisibility(0);

                } catch (Exception e) {
                    Log.i("LinkedinSample", "error to get verifier");
                    e.printStackTrace();
                }
            }
        });

        // set progress dialog
        progressDialog.setMessage("Loading...");
        progressDialog.setCancelable(true);
        progressDialog.show();
    }
}

LinkedinDialog.java

public class LinkedinDialog extends Dialog {
    private ProgressDialog progressDialog = null;

    public static LinkedInApiClientFactory factory;
    public static LinkedInOAuthService oAuthService;
    public static LinkedInRequestToken liToken;

    //Construct a new LinkedIn dialog

    public LinkedinDialog(Context context, ProgressDialog progressDialog) {
        super(context);
        this.progressDialog = progressDialog;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);// must call before super.
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ln_dialog);
        setWebView();
    }

    // set webview.
    private void setWebView() {
        LinkedinDialog.oAuthService = LinkedInOAuthServiceFactory.getInstance()
                .createLinkedInOAuthService(Config.LINKEDIN_CONSUMER_KEY,
                        Config.LINKEDIN_CONSUMER_SECRET);
        LinkedinDialog.factory = LinkedInApiClientFactory.newInstance(
                Config.LINKEDIN_CONSUMER_KEY, Config.LINKEDIN_CONSUMER_SECRET);

        LinkedinDialog.liToken = LinkedinDialog.oAuthService.getOAuthRequestToken(Config.OAUTH_CALLBACK_URL);

        WebView mWebView = (WebView) findViewById(R.id.webkitWebView1);
        mWebView.getSettings().setJavaScriptEnabled(true);

        Log.i("LinkedinSample", LinkedinDialog.liToken.getAuthorizationUrl());
        mWebView.loadUrl(LinkedinDialog.liToken.getAuthorizationUrl());
        mWebView.setWebViewClient(new HelloWebViewClient());

        mWebView.setPictureListener(new PictureListener() {
            @Override
            public void onNewPicture(WebView view, Picture picture) {
                if (progressDialog != null && progressDialog.isShowing()) {
                    progressDialog.dismiss();
                }

            }
        });

    }

    //webview client for internal url loading

    class HelloWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.contains(Config.OAUTH_CALLBACK_URL)) {
                Uri uri = Uri.parse(url);
                String verifier = uri.getQueryParameter("oauth_verifier");
                cancel();
                for (OnVerifyListener d : listeners) {
                    // call listener method
                    d.onVerify(verifier);
                }
            } else if (url.contains("https://www.linkedin.com/uas/oauth/redorangetechnologies.com")) {
                cancel();
            } else {
                Log.i("LinkedinSample", "url: " + url);
                view.loadUrl(url);
            }

            return true;
        }
    }

    /**
     * List of listener.
     */
    private List<OnVerifyListener> listeners = new ArrayList<OnVerifyListener>();

    /**
     * Register a callback to be invoked when authentication have finished.
     * 
     * @param data
     *            The callback that will run
     */
    public void setVerifierListener(OnVerifyListener data) {
        listeners.add(data);
    }

    /**
     * Listener for oauth_verifier.
     */
    interface OnVerifyListener {
        /**
         * invoked when authentication have finished.
         * 
         * @param verifier
         *            oauth_verifier code.
         */
        public void onVerify(String verifier);
    }
}

App crashed, on clicking login button, Error shows on setWebView(); in LinkedinDialog class.

Following is the logcat :

01-17 15:50:06.513: E/AndroidRuntime(2544): FATAL EXCEPTION: main
01-17 15:50:06.513: E/AndroidRuntime(2544): com.google.code.linkedinapi.client.oauth.LinkedInOAuthServiceException: oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: null
01-17 15:50:06.513: E/AndroidRuntime(2544):     at com.google.code.linkedinapi.client.oauth.LinkedInOAuthServiceImpl.getOAuthRequestToken(LinkedInOAuthServiceImpl.java:205)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at com.mukesh.linkedin.LinkedinDialog.setWebView(LinkedinDialog.java:65)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at com.mukesh.linkedin.LinkedinDialog.onCreate(LinkedinDialog.java:54)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at android.app.Dialog.dispatchOnCreate(Dialog.java:340)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at android.app.Dialog.show(Dialog.java:253)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at com.mukesh.linkedin.LinkedInSampleActivity.linkedInLogin(LinkedInSampleActivity.java:100)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at com.mukesh.linkedin.LinkedInSampleActivity.access$0(LinkedInSampleActivity.java:94)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at com.mukesh.linkedin.LinkedInSampleActivity$1.onClick(LinkedInSampleActivity.java:69)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at android.view.View.performClick(View.java:3480)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at android.view.View$PerformClick.run(View.java:13983)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at android.os.Handler.handleCallback(Handler.java:605)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at android.os.Looper.loop(Looper.java:137)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at android.app.ActivityThread.main(ActivityThread.java:4340)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at java.lang.reflect.Method.invokeNative(Native Method)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at java.lang.reflect.Method.invoke(Method.java:511)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at dalvik.system.NativeStart.main(Native Method)
01-17 15:50:06.513: E/AndroidRuntime(2544): Caused by: oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: null
01-17 15:50:06.513: E/AndroidRuntime(2544):     at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:214)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(AbstractOAuthProvider.java:69)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at com.google.code.linkedinapi.client.oauth.LinkedInOAuthServiceImpl.getOAuthRequestToken(LinkedInOAuthServiceImpl.java:196)
01-17 15:50:06.513: E/AndroidRuntime(2544):     ... 18 more
01-17 15:50:06.513: E/AndroidRuntime(2544): Caused by: android.os.NetworkOnMainThreadException
01-17 15:50:06.513: E/AndroidRuntime(2544):     at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1084)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at java.net.InetAddress.getAllByName(InetAddress.java:220)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at libcore.net.http.HttpConnection.<init>(HttpConnection.java:71)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:460)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:432)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at libcore.net.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:164)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at oauth.signpost.basic.DefaultOAuthProvider.sendRequest(DefaultOAuthProvider.java:48)
01-17 15:50:06.513: E/AndroidRuntime(2544):     at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:177)

解决方案

Add the below function after setContentView() in onCreate().

    if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy);
        }

This worked for me. Hope it will work for you.

这篇关于LinkedIn:oauth.signpost.exception.OAuthCommunicationException:与服务提供者的通信失败:空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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